mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-20 14:10:11 -07:00
Add LoaderBundle tests
This commit is contained in:
parent
edcb7fa98d
commit
9089929e66
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LoaderBundle\Exception\Loader;
|
||||||
|
|
||||||
|
class LoadingRebrickableFailedException extends \Exception
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LoaderBundle\Exception\RelationMapper;
|
||||||
|
|
||||||
|
class InvalidDomainException extends \LogicException
|
||||||
|
{
|
||||||
|
}
|
@ -5,11 +5,9 @@ namespace LoaderBundle\Service;
|
|||||||
use AppBundle\Transformer\FormatTransformer;
|
use AppBundle\Transformer\FormatTransformer;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use LoaderBundle\Exception\FileNotFoundException;
|
|
||||||
use LoaderBundle\Exception\WriteErrorException;
|
use LoaderBundle\Exception\WriteErrorException;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Asset\Exception\LogicException;
|
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@ -101,28 +99,22 @@ abstract class BaseLoader
|
|||||||
*
|
*
|
||||||
* @param $url
|
* @param $url
|
||||||
*
|
*
|
||||||
* @throws FileNotFoundException
|
* @throws WriteErrorException
|
||||||
*
|
*
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
protected function downloadFile($url)
|
protected function downloadFile($url)
|
||||||
{
|
{
|
||||||
$this->output->writeln('Loading file from: <comment>'.$url.'</comment>');
|
$this->writeOutput(['Loading file from: <comment>'.$url.'</comment>']);
|
||||||
$temp = tempnam(sys_get_temp_dir(), 'printabrick.');
|
$temp = tempnam(sys_get_temp_dir(), 'printabrick.');
|
||||||
|
|
||||||
$ctx = stream_context_create([], [
|
$ctx = stream_context_create([], [
|
||||||
'notification' => [$this, 'progressCallback'],
|
'notification' => [$this, 'progressCallback'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
|
||||||
if (false === file_put_contents($temp, fopen($url, 'r', 0, $ctx))) {
|
if (false === file_put_contents($temp, fopen($url, 'r', 0, $ctx))) {
|
||||||
throw new WriteErrorException($temp);
|
throw new WriteErrorException($temp);
|
||||||
}
|
}
|
||||||
} catch (\ErrorException $e) {
|
|
||||||
throw new FileNotFoundException($url);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new LogicException($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $temp;
|
return $temp;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace LoaderBundle\Service;
|
|||||||
use AppBundle\Entity\LDraw\Model;
|
use AppBundle\Entity\LDraw\Model;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use League\Flysystem\FilesystemInterface;
|
use League\Flysystem\FilesystemInterface;
|
||||||
|
use LoaderBundle\Exception\FileException;
|
||||||
use LoaderBundle\Service\Stl\StlRendererService;
|
use LoaderBundle\Service\Stl\StlRendererService;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ class ImageLoader extends BaseLoader
|
|||||||
* Download ZIP file with part images from rebrickable and unzip file to filesystem.
|
* Download ZIP file with part images from rebrickable and unzip file to filesystem.
|
||||||
*
|
*
|
||||||
* @param int $color color id used by rebrickable
|
* @param int $color color id used by rebrickable
|
||||||
|
*
|
||||||
|
* @throws FileException
|
||||||
*/
|
*/
|
||||||
public function loadColorFromRebrickable($color)
|
public function loadColorFromRebrickable($color)
|
||||||
{
|
{
|
||||||
@ -41,14 +44,15 @@ class ImageLoader extends BaseLoader
|
|||||||
$zip = new \ZipArchive($file);
|
$zip = new \ZipArchive($file);
|
||||||
|
|
||||||
if ($zip->open($file) === true) {
|
if ($zip->open($file) === true) {
|
||||||
$this->output->writeln([
|
$this->writeOutput([
|
||||||
"Extracting ZIP file into {$this->mediaFilesystem->getAdapter()->getPathPrefix()}images/{$color}",
|
"Extracting ZIP file into {$this->mediaFilesystem->getAdapter()->getPathPrefix()}images/{$color}",
|
||||||
]);
|
]);
|
||||||
$zip->extractTo($this->mediaFilesystem->getAdapter()->getPathPrefix().'images'.DIRECTORY_SEPARATOR.$color);
|
$zip->extractTo($this->mediaFilesystem->getAdapter()->getPathPrefix().'images'.DIRECTORY_SEPARATOR.$color);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
$this->output->writeln(['Done!']);
|
$this->writeOutput(['Done!']);
|
||||||
} else {
|
} else {
|
||||||
$this->logger->error('Extraction of file failed!');
|
$this->logger->error('Extraction of file failed!');
|
||||||
|
throw new FileException($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +73,7 @@ class ImageLoader extends BaseLoader
|
|||||||
unset($models);
|
unset($models);
|
||||||
|
|
||||||
// Render images
|
// Render images
|
||||||
$this->output->writeln([
|
$this->writeOutput([
|
||||||
'Rendering missing images of models',
|
'Rendering missing images of models',
|
||||||
]);
|
]);
|
||||||
$this->initProgressBar(count($missing));
|
$this->initProgressBar(count($missing));
|
||||||
@ -79,7 +83,7 @@ class ImageLoader extends BaseLoader
|
|||||||
try {
|
try {
|
||||||
$this->loadModelImage($this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath());
|
$this->loadModelImage($this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->error('Error rendering model '.$model->getId().' image', $e);
|
$this->logger->error('Error rendering model '.$model->getId().' image');
|
||||||
}
|
}
|
||||||
$this->progressBar->advance();
|
$this->progressBar->advance();
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@ class ModelLoader extends BaseLoader
|
|||||||
'<fg=cyan>------------------------------------------------------------------------------</>',
|
'<fg=cyan>------------------------------------------------------------------------------</>',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
$libraryZip = $this->downloadFile($url);
|
$libraryZip = $this->downloadFile($url);
|
||||||
|
|
||||||
$temp_dir = tempnam(sys_get_temp_dir(), 'printabrick.');
|
$temp_dir = tempnam(sys_get_temp_dir(), 'printabrick.');
|
||||||
@ -111,9 +112,7 @@ class ModelLoader extends BaseLoader
|
|||||||
mkdir($temp_dir);
|
mkdir($temp_dir);
|
||||||
|
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
if ($zip->open($libraryZip) != 'true') {
|
$zip->open($libraryZip);
|
||||||
echo 'Error :- Unable to open the Zip File';
|
|
||||||
}
|
|
||||||
$zip->extractTo($temp_dir);
|
$zip->extractTo($temp_dir);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unlink($libraryZip);
|
unlink($libraryZip);
|
||||||
@ -124,6 +123,9 @@ class ModelLoader extends BaseLoader
|
|||||||
if (file_exists($temp_dir.'/ldraw/')) {
|
if (file_exists($temp_dir.'/ldraw/')) {
|
||||||
return $temp_dir.'/ldraw/';
|
return $temp_dir.'/ldraw/';
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
throw new \LogicException('Falied to open Zip archive');
|
||||||
|
}
|
||||||
|
|
||||||
return $temp_dir;
|
return $temp_dir;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use AppBundle\Entity\Rebrickable\Part;
|
|||||||
use AppBundle\Entity\Rebrickable\Set;
|
use AppBundle\Entity\Rebrickable\Set;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Query\Expr\Join;
|
use Doctrine\ORM\Query\Expr\Join;
|
||||||
|
use LoaderBundle\Exception\Loader\LoadingRebrickableFailedException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
//TODO Refactor + validate csv files
|
//TODO Refactor + validate csv files
|
||||||
@ -30,9 +31,9 @@ class RebrickableLoader extends BaseLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncates and loads all rebrickable tables from csv files
|
* Truncates and loads all rebrickable tables from csv files.
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws LoadingRebrickableFailedException
|
||||||
*/
|
*/
|
||||||
public function loadAll()
|
public function loadAll()
|
||||||
{
|
{
|
||||||
@ -67,19 +68,19 @@ class RebrickableLoader extends BaseLoader
|
|||||||
|
|
||||||
$this->writeOutput(['Rebrickable database loaded successfully!']);
|
$this->writeOutput(['Rebrickable database loaded successfully!']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->writeOutput(['Rollback back']);
|
// $this->writeOutput(['Rollback back']);
|
||||||
$connection->rollBack();
|
// $connection->rollBack();
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
throw new LoadingRebrickableFailedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads csv files from rebrickable_url specified in config.yml
|
* Downloads csv files from rebrickable_url specified in config.yml.
|
||||||
*/
|
*/
|
||||||
private function loadCSVFiles()
|
private function loadCSVFiles()
|
||||||
{
|
{
|
||||||
$array = ['inventories', 'inventory_parts', 'inventory_sets', 'sets', 'themes', 'parts', 'part_categories', 'colors'];
|
$array = ['inventories', 'inventory_parts', 'inventory_sets', 'sets', 'themes', 'parts', 'part_categories'];
|
||||||
|
|
||||||
$this->writeOutput([
|
$this->writeOutput([
|
||||||
'<fg=cyan>------------------------------------------------------------------------------</>',
|
'<fg=cyan>------------------------------------------------------------------------------</>',
|
||||||
@ -133,6 +134,9 @@ class RebrickableLoader extends BaseLoader
|
|||||||
return $this->em->getConnection()->prepare($query)->execute();
|
return $this->em->getConnection()->prepare($query)->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates missing Part entites for foreign keys form inventory_parts table.
|
||||||
|
*/
|
||||||
private function addMissingParts()
|
private function addMissingParts()
|
||||||
{
|
{
|
||||||
$connection = $this->em->getConnection();
|
$connection = $this->em->getConnection();
|
||||||
@ -185,8 +189,8 @@ class RebrickableLoader extends BaseLoader
|
|||||||
return $this->loadCsvFile($csv, 'rebrickable_category', '(`id`,`name`)');
|
return $this->loadCsvFile($csv, 'rebrickable_category', '(`id`,`name`)');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadColorTable($csv)
|
// private function loadColorTable($csv)
|
||||||
{
|
// {
|
||||||
return $this->loadCsvFile($csv, 'color', '(`id`,`name`,`rgb`, @var) SET transparent = IF(@var=\'t\',1,0)');
|
// return $this->loadCsvFile($csv, 'color', '(`id`,`name`,`rgb`, @var) SET transparent = IF(@var=\'t\',1,0)');
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -93,67 +93,11 @@ class StlConverterService
|
|||||||
|
|
||||||
return $this->mediaFilesystem->get($newFile);
|
return $this->mediaFilesystem->get($newFile);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return $this->mediaFilesystem->get($newFile);
|
return $this->mediaFilesystem->get($newFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ConvertingFailedException($file, 'STL');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert LDraw model from .dat format to .stl by using LDView
|
|
||||||
* stores created file to $stlStorage filesystem.
|
|
||||||
*
|
|
||||||
* @param string $file
|
|
||||||
* @param bool $rewrite
|
|
||||||
*
|
|
||||||
* @throws ConvertingFailedException
|
|
||||||
*
|
|
||||||
* @return File
|
|
||||||
*/
|
|
||||||
public function datToPng($file, $rewrite = false)
|
|
||||||
{
|
|
||||||
if (!$this->ldrawLibraryContext) {
|
|
||||||
throw new LDLibraryMissingException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->mediaFilesystem->has('images')) {
|
|
||||||
$this->mediaFilesystem->createDir('images');
|
|
||||||
}
|
|
||||||
|
|
||||||
$newFile = 'images'.DIRECTORY_SEPARATOR.basename($file, '.dat').'.png';
|
|
||||||
|
|
||||||
if (!$this->mediaFilesystem->has($newFile) || $rewrite) {
|
|
||||||
$this->runLDView([
|
|
||||||
$file,
|
|
||||||
'-LDrawDir='.$this->ldrawLibraryContext->getAdapter()->getPathPrefix(),
|
|
||||||
'-AutoCrop=0',
|
|
||||||
'-SaveAlpha=0',
|
|
||||||
'-BackgroundColor3=0xFFFFFF',
|
|
||||||
'-DefaultColor3=0x136FC3',
|
|
||||||
'-SnapshotSuffix=.png',
|
|
||||||
'-HiResPrimitives=1',
|
|
||||||
'-UseQualityStuds=1',
|
|
||||||
'-UseQualityLighting=1',
|
|
||||||
'-SaveHeight=600',
|
|
||||||
'-SaveWidth=800',
|
|
||||||
'-CurveQuality=12',
|
|
||||||
'-DefaultLatLong=45,40',
|
|
||||||
'-SaveDir='.$this->mediaFilesystem->getAdapter()->getPathPrefix().'images',
|
|
||||||
'-SaveSnapshots=1',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Check if file created successfully
|
|
||||||
if ($this->mediaFilesystem->has($newFile)) {
|
|
||||||
return $this->mediaFilesystem->get($newFile);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->mediaFilesystem->get($newFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ConvertingFailedException($file, 'PNG');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call LDView process with $arguments.
|
* Call LDView process with $arguments.
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,7 @@ namespace LoaderBundle\Service\Stl;
|
|||||||
use LoaderBundle\Exception\ConvertingFailedException;
|
use LoaderBundle\Exception\ConvertingFailedException;
|
||||||
use LoaderBundle\Exception\FileNotFoundException;
|
use LoaderBundle\Exception\FileNotFoundException;
|
||||||
use LoaderBundle\Exception\RenderFailedException;
|
use LoaderBundle\Exception\RenderFailedException;
|
||||||
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
use Symfony\Component\Process\ProcessBuilder;
|
use Symfony\Component\Process\ProcessBuilder;
|
||||||
|
|
||||||
@ -101,9 +102,6 @@ class StlRendererService
|
|||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
throw new FileNotFoundException($file);
|
throw new FileNotFoundException($file);
|
||||||
}
|
}
|
||||||
if (pathinfo($file, PATHINFO_EXTENSION) != 'stl') {
|
|
||||||
throw new ConvertingFailedException($file, 'POV', 'Wrong input filetype');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the current working directory and change directory to tmp dir
|
// Save the current working directory and change directory to tmp dir
|
||||||
// stl2pov outputs converted file to current directory and destination can not be changed
|
// stl2pov outputs converted file to current directory and destination can not be changed
|
||||||
@ -195,7 +193,8 @@ class StlRendererService
|
|||||||
//+AMn - use non-adaptive (n=1) or adaptive (n=2) supersampling
|
//+AMn - use non-adaptive (n=1) or adaptive (n=2) supersampling
|
||||||
//+A0.n - perform antialiasing (if color change is above n percent)
|
//+A0.n - perform antialiasing (if color change is above n percent)
|
||||||
//-D - Turns graphic display off
|
//-D - Turns graphic display off
|
||||||
$process = $processBuilder->setPrefix($this->povray)
|
$process = $processBuilder
|
||||||
|
->setPrefix($this->povray)
|
||||||
->setArguments([
|
->setArguments([
|
||||||
"+I\"{$file}\"",
|
"+I\"{$file}\"",
|
||||||
'+FN',
|
'+FN',
|
||||||
@ -207,8 +206,13 @@ class StlRendererService
|
|||||||
'+A0.5',
|
'+A0.5',
|
||||||
'-D',
|
'-D',
|
||||||
])->getProcess();
|
])->getProcess();
|
||||||
|
|
||||||
$process->mustRun();
|
$process->mustRun();
|
||||||
|
|
||||||
|
if (!$process->isSuccessful()) {
|
||||||
|
throw new ProcessFailedException($process);
|
||||||
|
}
|
||||||
|
|
||||||
if (!file_exists($outputFile)) {
|
if (!file_exists($outputFile)) {
|
||||||
throw new RenderFailedException("{$to}{$filename}.png");
|
throw new RenderFailedException("{$to}{$filename}.png");
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
namespace LoaderBundle\Util;
|
namespace LoaderBundle\Util;
|
||||||
|
|
||||||
use Doctrine\Common\Cache\CacheProvider;
|
use Doctrine\Common\Cache\CacheProvider;
|
||||||
|
use LoaderBundle\Exception\RelationMapper\InvalidDomainException;
|
||||||
use LoaderBundle\Exception\RelationMapper\InvalidResourceException;
|
use LoaderBundle\Exception\RelationMapper\InvalidResourceException;
|
||||||
use LoaderBundle\Exception\RelationMapper\ResourceNotFoundException;
|
use LoaderBundle\Exception\RelationMapper\ResourceNotFoundException;
|
||||||
use Symfony\Component\OptionsResolver\Exception\InvalidArgumentException;
|
use Symfony\Component\OptionsResolver\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
|
||||||
use Symfony\Component\Yaml\Exception\ParseException;
|
use Symfony\Component\Yaml\Exception\ParseException;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
@ -69,6 +69,6 @@ class RelationMapper
|
|||||||
if (isset($this->relations[$domain])) {
|
if (isset($this->relations[$domain])) {
|
||||||
return isset($this->relations[$domain][$number]) ? $this->relations[$domain][$number] : $number;
|
return isset($this->relations[$domain][$number]) ? $this->relations[$domain][$number] : $number;
|
||||||
}
|
}
|
||||||
throw new InvalidOptionsException();
|
throw new InvalidDomainException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
62
tests/LoaderBundle/Service/ImageLoader/ImageLoaderTest.php
Normal file
62
tests/LoaderBundle/Service/ImageLoader/ImageLoaderTest.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\LoaderBundle\Service;
|
||||||
|
|
||||||
|
use League\Flysystem\File;
|
||||||
|
use LoaderBundle\Service\ImageLoader;
|
||||||
|
use LoaderBundle\Service\Stl\StlRendererService;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
|
use Tests\AppBundle\BaseTest;
|
||||||
|
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||||
|
|
||||||
|
class ImageLoaderTest extends BaseTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var ImageLoader
|
||||||
|
*/
|
||||||
|
private $imageLoader;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->setUpDb([LoadBaseData::class]);
|
||||||
|
|
||||||
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('getPath')->willReturn('path');
|
||||||
|
|
||||||
|
$stlRenderer = $this->createMock(StlRendererService::class);
|
||||||
|
$stlRenderer->method('render')->willReturn('image');
|
||||||
|
|
||||||
|
$this->imageLoader = new ImageLoader($this->em, $this->get('monolog.logger.event'), $this->filesystem, __DIR__.'/fixtures/', $stlRenderer);
|
||||||
|
$this->imageLoader->setOutput(new NullOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadFromRebrickable()
|
||||||
|
{
|
||||||
|
$this->imageLoader->loadColorFromRebrickable(-1);
|
||||||
|
|
||||||
|
$this->assertCount(8, $this->filesystem->listContents('images/-1/'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LoaderBundle\Exception\FileException
|
||||||
|
*/
|
||||||
|
public function testLoadCorrupted()
|
||||||
|
{
|
||||||
|
$this->imageLoader->loadColorFromRebrickable(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadMissingImages()
|
||||||
|
{
|
||||||
|
$stlRenderer = $this->createMock(StlRendererService::class);
|
||||||
|
$stlRenderer->method('render')->willReturn('image');
|
||||||
|
|
||||||
|
$stlRenderer->expects($this->exactly(3))->method('render');
|
||||||
|
|
||||||
|
$this->imageLoader = new ImageLoader($this->em, $this->get('monolog.logger.event'), $this->filesystem, __DIR__.'/fixtures/', $stlRenderer);
|
||||||
|
$this->imageLoader->setOutput(new NullOutput());
|
||||||
|
|
||||||
|
$this->imageLoader->loadMissingModelImages();
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\LoaderBundle\Service\ModelLoader;
|
namespace Tests\LoaderBundle\Service;
|
||||||
|
|
||||||
|
use AppBundle\DataFixtures\ORM\LoadColors;
|
||||||
use AppBundle\Entity\LDraw\Alias;
|
use AppBundle\Entity\LDraw\Alias;
|
||||||
use AppBundle\Entity\LDraw\Model;
|
use AppBundle\Entity\LDraw\Model;
|
||||||
use AppBundle\Repository\LDraw\AliasRepository;
|
use AppBundle\Repository\LDraw\AliasRepository;
|
||||||
use AppBundle\Repository\LDraw\ModelRepository;
|
use AppBundle\Repository\LDraw\ModelRepository;
|
||||||
|
use League\Flysystem\File;
|
||||||
use LoaderBundle\Service\ModelLoader;
|
use LoaderBundle\Service\ModelLoader;
|
||||||
use LoaderBundle\Service\Stl\StlConverterService;
|
use LoaderBundle\Service\Stl\StlConverterService;
|
||||||
use LoaderBundle\Util\RelationMapper;
|
use LoaderBundle\Util\RelationMapper;
|
||||||
use League\Flysystem\File;
|
|
||||||
use League\Flysystem\Filesystem;
|
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
use Tests\AppBundle\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
@ -47,9 +47,9 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$relationMapper->method('find')
|
$relationMapper->method('find')
|
||||||
->will($this->returnArgument(0));
|
->will($this->returnArgument(0));
|
||||||
|
|
||||||
$this->modelLoader = new ModelLoader($this->get('doctrine.orm.entity_manager'),$this->get('monolog.logger.event'),$stlConverter,$relationMapper,null);
|
$this->modelLoader = new ModelLoader($this->em, $this->get('monolog.logger.event'), $stlConverter, $relationMapper);
|
||||||
$this->modelLoader->setOutput(new NullOutput());
|
$this->modelLoader->setOutput(new NullOutput());
|
||||||
$this->setUpDb();
|
$this->setUpDb([LoadColors::class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadOne()
|
public function testLoadOne()
|
||||||
@ -169,7 +169,8 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$this->assertEquals(2010, $model->getModified()->format('Y'));
|
$this->assertEquals(2010, $model->getModified()->format('Y'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadOfPrinted() {
|
public function testLoadOfPrinted()
|
||||||
|
{
|
||||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/printed/');
|
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/printed/');
|
||||||
$this->modelLoader->loadOne(__DIR__.'/fixtures/printed/parts/30367bps7.dat');
|
$this->modelLoader->loadOne(__DIR__.'/fixtures/printed/parts/30367bps7.dat');
|
||||||
|
|
||||||
@ -178,4 +179,21 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$this->assertEquals(1, count($models));
|
$this->assertEquals(1, count($models));
|
||||||
$this->assertEquals('30367b', $models[0]->getId());
|
$this->assertEquals('30367b', $models[0]->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDownload()
|
||||||
|
{
|
||||||
|
$library = $this->modelLoader->downloadLibrary(__DIR__.'/fixtures/ldraw.zip');
|
||||||
|
|
||||||
|
$this->assertDirectoryExists($library);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LogicException
|
||||||
|
*/
|
||||||
|
public function testDownloadFailed()
|
||||||
|
{
|
||||||
|
$library = $this->modelLoader->downloadLibrary(__DIR__.'/fixtures/nofile.zip');
|
||||||
|
|
||||||
|
$this->assertDirectoryExists($library);
|
||||||
|
}
|
||||||
}
|
}
|
BIN
tests/LoaderBundle/Service/ModelLoader/fixtures/ldraw.zip
Normal file
BIN
tests/LoaderBundle/Service/ModelLoader/fixtures/ldraw.zip
Normal file
Binary file not shown.
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\LoaderBundle\Service;
|
||||||
|
|
||||||
|
use AppBundle\DataFixtures\ORM\LoadColors;
|
||||||
|
use AppBundle\Entity\Rebrickable\Set;
|
||||||
|
use LoaderBundle\Service\RebrickableLoader;
|
||||||
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
|
class RebrickableLoaderTest extends BaseTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RebrickableLoader
|
||||||
|
*/
|
||||||
|
private $rebrickableLoader;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->setUpDb([LoadColors::class]);
|
||||||
|
|
||||||
|
$this->rebrickableLoader = new RebrickableLoader($this->em, $this->get('monolog.logger.event'), __DIR__.'/fixtures/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadAll()
|
||||||
|
{
|
||||||
|
$this->assertCount(0, $this->em->getRepository(Set::class)->findAll());
|
||||||
|
$this->rebrickableLoader->loadAll();
|
||||||
|
|
||||||
|
$this->assertCount(1, $this->em->getRepository(Set::class)->findAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @expectedException LoaderBundle\Exception\Loader\LoadingRebrickableFailedException
|
||||||
|
// */
|
||||||
|
// public function testRollback() {
|
||||||
|
// $this->rebrickableLoader = new RebrickableLoader($this->em,$this->get('monolog.logger.event'),__DIR__.'/corrupt/');
|
||||||
|
//
|
||||||
|
// $this->assertCount(0,$this->em->getRepository(Set::class)->findAll());
|
||||||
|
//
|
||||||
|
// $this->rebrickableLoader->loadAll();
|
||||||
|
//
|
||||||
|
// $this->assertCount(0,$this->em->getRepository(Set::class)->findAll());
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
id,version,set_num
|
||||||
|
4609,1,0013-1
|
|
@ -0,0 +1,8 @@
|
|||||||
|
inventory_id,part_num,color_id,quantity,is_spare
|
||||||
|
4609,3626apr0001,14,2,f
|
||||||
|
4609,3838,15,2,f
|
||||||
|
4609,3842a,15,2,f
|
||||||
|
4609,3962a,0,2,f
|
||||||
|
4609,970c00,15,2,f
|
||||||
|
4609,973p90c05,15,2,f
|
||||||
|
4609,255,15,2,f
|
|
@ -0,0 +1 @@
|
|||||||
|
inventory_id,set_num,quantity
|
|
@ -0,0 +1,3 @@
|
|||||||
|
,id,name,dasd
|
||||||
|
,,13,Minifigs,,
|
||||||
|
27,Minifig Accessories
|
|
@ -0,0 +1,7 @@
|
|||||||
|
part_num,name,part_cat_id
|
||||||
|
3626apr0001,Minifig Head Standard Grin Print [Solid Stud],13
|
||||||
|
3838,Minifig Airtanks,27
|
||||||
|
3842a,Minifig Helmet Classic with Thin Chin Guard and Visor Dimples,27
|
||||||
|
3962a,Minifig Radio [Compact Handle],27
|
||||||
|
970c00,Legs and Hips [Complete Assembly],13
|
||||||
|
973p90c05,Torso Space Classic Moon Print / White Arms / White Hands,13
|
|
@ -0,0 +1,2 @@
|
|||||||
|
set_num,name,year,theme_id,num_parts
|
||||||
|
0013-1,Space Mini-Figures,1979,143,12
|
|
@ -0,0 +1,3 @@
|
|||||||
|
id,name,parent_id
|
||||||
|
126,Space,
|
||||||
|
143,Supplemental,126
|
|
@ -0,0 +1,2 @@
|
|||||||
|
id,version,set_num
|
||||||
|
4609,1,0013-1
|
|
@ -0,0 +1,8 @@
|
|||||||
|
inventory_id,part_num,color_id,quantity,is_spare
|
||||||
|
4609,3626apr0001,14,2,f
|
||||||
|
4609,3838,15,2,f
|
||||||
|
4609,3842a,15,2,f
|
||||||
|
4609,3962a,0,2,f
|
||||||
|
4609,970c00,15,2,f
|
||||||
|
4609,973p90c05,15,2,f
|
||||||
|
4609,255,15,2,f
|
|
@ -0,0 +1 @@
|
|||||||
|
inventory_id,set_num,quantity
|
|
@ -0,0 +1,3 @@
|
|||||||
|
id,name
|
||||||
|
13,Minifigs
|
||||||
|
27,Minifig Accessories
|
|
@ -0,0 +1,7 @@
|
|||||||
|
part_num,name,part_cat_id
|
||||||
|
3626apr0001,Minifig Head Standard Grin Print [Solid Stud],13
|
||||||
|
3838,Minifig Airtanks,27
|
||||||
|
3842a,Minifig Helmet Classic with Thin Chin Guard and Visor Dimples,27
|
||||||
|
3962a,Minifig Radio [Compact Handle],27
|
||||||
|
970c00,Legs and Hips [Complete Assembly],13
|
||||||
|
973p90c05,Torso Space Classic Moon Print / White Arms / White Hands,13
|
|
@ -0,0 +1,2 @@
|
|||||||
|
set_num,name,year,theme_id,num_parts
|
||||||
|
0013-1,Space Mini-Figures,1979,143,12
|
|
@ -0,0 +1,3 @@
|
|||||||
|
id,name,parent_id
|
||||||
|
126,Space,
|
||||||
|
143,Supplemental,126
|
|
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\LoaderBundle\Service;
|
||||||
|
|
||||||
|
use AppBundle\Entity\Rebrickable\Part;
|
||||||
|
use League\Flysystem\File;
|
||||||
|
use LoaderBundle\Service\RelationLoader;
|
||||||
|
use LoaderBundle\Util\RelationMapper;
|
||||||
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
|
use Tests\AppBundle\BaseTest;
|
||||||
|
use Tests\AppBundle\Fixtures\LoadUnmappedData;
|
||||||
|
|
||||||
|
class RelationLoaderTest extends BaseTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RelationLoader
|
||||||
|
*/
|
||||||
|
private $relationLoader;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->setUpDb([LoadUnmappedData::class]);
|
||||||
|
|
||||||
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('getPath')->willReturn('path');
|
||||||
|
|
||||||
|
$relationMapper = $this->createMock(RelationMapper::class);
|
||||||
|
$relationMapper->method('find')->will($this->returnArgument(0));
|
||||||
|
|
||||||
|
$this->relationLoader = new RelationLoader($this->get('doctrine.orm.entity_manager'), $this->get('monolog.logger.event'), $relationMapper);
|
||||||
|
$this->relationLoader->setOutput(new NullOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadAll()
|
||||||
|
{
|
||||||
|
$this->relationLoader->loadAll();
|
||||||
|
|
||||||
|
$parts = $this->em->getRepository(Part::class)->findAll();
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$this->assertNotNull($part->getModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadNotPaired()
|
||||||
|
{
|
||||||
|
$this->relationLoader->loadNotPaired();
|
||||||
|
|
||||||
|
$parts = $this->em->getRepository(Part::class)->findAll();
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$this->assertNotNull($part->getModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace Tests\AppBundle\Service\Stl;
|
namespace Tests\AppBundle\Service\Stl;
|
||||||
|
|
||||||
use LoaderBundle\Service\Stl\StlConverterService;
|
|
||||||
use LoaderBundle\Service\Stl\StlFixerService;
|
|
||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
|
use LoaderBundle\Service\Stl\StlConverterService;
|
||||||
|
use LoaderBundle\Service\Stl\StlFixerService;
|
||||||
use Tests\AppBundle\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class StlConverterTest extends BaseTest
|
class StlConverterTest extends BaseTest
|
||||||
@ -13,7 +13,6 @@ class StlConverterTest extends BaseTest
|
|||||||
/** @var StlConverterService */
|
/** @var StlConverterService */
|
||||||
private $stlConverter;
|
private $stlConverter;
|
||||||
|
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -35,28 +34,58 @@ class StlConverterTest extends BaseTest
|
|||||||
$this->assertNotNull($this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat'));
|
$this->assertNotNull($this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat'));
|
||||||
|
|
||||||
$this->assertTrue($this->filesystem->has('models/983.stl'));
|
$this->assertTrue($this->filesystem->has('models/983.stl'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->filesystem->delete('models/983.stl');
|
public function testRewriteTrue()
|
||||||
|
{
|
||||||
|
$adapter = new Local(__DIR__.'/fixtures/ldraw');
|
||||||
|
$ldrawLibraryContext = new Filesystem($adapter);
|
||||||
|
$this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext);
|
||||||
|
|
||||||
|
$this->filesystem->write('models/983.stl', file_get_contents(__DIR__.'/fixtures/983.stl'));
|
||||||
|
$this->assertTrue($this->filesystem->has('models/983.stl'));
|
||||||
|
|
||||||
|
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat', true);
|
||||||
|
|
||||||
|
$this->assertEquals(file_get_contents(__DIR__.'/fixtures/expected.stl'), $this->filesystem->read('models/983.stl'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRewriteFalse()
|
||||||
|
{
|
||||||
|
$adapter = new Local(__DIR__.'/fixtures/ldraw');
|
||||||
|
$ldrawLibraryContext = new Filesystem($adapter);
|
||||||
|
$this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext);
|
||||||
|
|
||||||
|
$this->filesystem->write('models/983.stl', file_get_contents(__DIR__.'/fixtures/983.stl'));
|
||||||
|
$this->assertTrue($this->filesystem->has('models/983.stl'));
|
||||||
|
|
||||||
|
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
||||||
|
|
||||||
|
$this->assertEquals(file_get_contents(__DIR__.'/fixtures/983.stl'), $this->filesystem->read('models/983.stl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException LoaderBundle\Exception\Stl\LDLibraryMissingException
|
* @expectedException \LoaderBundle\Exception\Stl\LDLibraryMissingException
|
||||||
*/
|
*/
|
||||||
public function testLDContextMissing()
|
public function testLDContextMissing()
|
||||||
{
|
{
|
||||||
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConvertToPng()
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
|
||||||
|
*/
|
||||||
|
public function testProcessFailedException()
|
||||||
{
|
{
|
||||||
|
$stlFixer = $this->createMock(StlFixerService::class);
|
||||||
|
$stlFixer->method('fix');
|
||||||
|
|
||||||
|
$this->stlConverter = new StlConverterService('', $this->filesystem, $stlFixer);
|
||||||
|
|
||||||
$adapter = new Local(__DIR__.'/fixtures/ldraw');
|
$adapter = new Local(__DIR__.'/fixtures/ldraw');
|
||||||
$ldrawLibraryContext = new Filesystem($adapter);
|
$ldrawLibraryContext = new Filesystem($adapter);
|
||||||
$this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext);
|
$this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext);
|
||||||
|
|
||||||
$this->assertNotNull($this->stlConverter->datToPng(__DIR__ . '/fixtures/ldraw/parts/983.dat'));
|
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
||||||
|
|
||||||
$this->assertTrue($this->filesystem->has('images/983.png'));
|
|
||||||
|
|
||||||
$this->filesystem->delete('images/983.png');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
tests/LoaderBundle/Service/Stl/StlConverter/fixtures/983.stl
Normal file
BIN
tests/LoaderBundle/Service/Stl/StlConverter/fixtures/983.stl
Normal file
Binary file not shown.
1262
tests/LoaderBundle/Service/Stl/StlConverter/fixtures/expected.stl
Normal file
1262
tests/LoaderBundle/Service/Stl/StlConverter/fixtures/expected.stl
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,12 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\AppBundle\Service\Stl;
|
namespace Tests\AppBundle\Service\Stl;
|
||||||
|
|
||||||
use LoaderBundle\Service\Stl\StlConverterService;
|
|
||||||
use LoaderBundle\Service\Stl\StlFixerService;
|
use LoaderBundle\Service\Stl\StlFixerService;
|
||||||
use League\Flysystem\Adapter\Local;
|
|
||||||
use League\Flysystem\Filesystem;
|
|
||||||
use League\Flysystem\FilesystemInterface;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Tests\AppBundle\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class StlFixer extends BaseTest
|
class StlFixer extends BaseTest
|
||||||
@ -25,15 +20,27 @@ class StlFixer extends BaseTest
|
|||||||
$this->input = __DIR__.'/fixtures/ascii.stl';
|
$this->input = __DIR__.'/fixtures/ascii.stl';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->filesystem->delete('output.stl');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFixing()
|
public function testFixing()
|
||||||
{
|
{
|
||||||
$this->stlFixer->fix($this->input, $this->filesystem->getAdapter()->getPathPrefix().'/output.stl');
|
$this->stlFixer->fix($this->input, $this->filesystem->getAdapter()->getPathPrefix().'/output.stl');
|
||||||
|
|
||||||
$this->assertTrue($this->filesystem->has('output.stl'));
|
$this->assertTrue($this->filesystem->has('output.stl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LoaderBundle\Exception\FileNotFoundException
|
||||||
|
*/
|
||||||
|
public function testFileNotFound()
|
||||||
|
{
|
||||||
|
$this->stlFixer->fix('', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
|
||||||
|
*/
|
||||||
|
public function testCorruptProcess()
|
||||||
|
{
|
||||||
|
$this->stlFixer = new StlFixerService('');
|
||||||
|
$this->stlFixer->fix($this->input);
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,13 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\AppBundle\Service\Stl;
|
namespace Tests\AppBundle\Service\Stl;
|
||||||
|
|
||||||
use LoaderBundle\Service\Stl\StlConverterService;
|
|
||||||
use LoaderBundle\Service\Stl\StlFixerService;
|
|
||||||
use LoaderBundle\Service\Stl\StlRendererService;
|
use LoaderBundle\Service\Stl\StlRendererService;
|
||||||
use League\Flysystem\Adapter\Local;
|
|
||||||
use League\Flysystem\Filesystem;
|
|
||||||
use League\Flysystem\FilesystemInterface;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Tests\AppBundle\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class StlRendererTest extends BaseTest
|
class StlRendererTest extends BaseTest
|
||||||
@ -27,14 +21,30 @@ class StlRendererTest extends BaseTest
|
|||||||
$this->stlRenderer = new StlRendererService($layout, $povray, $stl2pov);
|
$this->stlRenderer = new StlRendererService($layout, $povray, $stl2pov);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
$this->filesystem->delete('973c00.png');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRendering()
|
public function testRendering()
|
||||||
{
|
{
|
||||||
$this->stlRenderer->render(__DIR__.'/fixtures/973c00.stl', $this->filesystem->getAdapter()->getPathPrefix());
|
$this->stlRenderer->render(__DIR__.'/fixtures/973c00.stl', $this->filesystem->getAdapter()->getPathPrefix());
|
||||||
$this->assertTrue($this->filesystem->has('973c00.png'));
|
$this->assertTrue($this->filesystem->has('973c00.png'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LoaderBundle\Exception\FileNotFoundException
|
||||||
|
*/
|
||||||
|
public function testFileNotFound()
|
||||||
|
{
|
||||||
|
$this->stlRenderer->render('abc', $this->filesystem->getAdapter()->getPathPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
|
||||||
|
*/
|
||||||
|
public function testPovRayMissing()
|
||||||
|
{
|
||||||
|
$layout = __DIR__.'/fixtures/layout.tmpl';
|
||||||
|
$stl2pov = $this->getParameter('stl2pov_bin');
|
||||||
|
$this->stlRenderer = new StlRendererService($layout, '', $stl2pov);
|
||||||
|
|
||||||
|
$this->stlRenderer->render(__DIR__.'/fixtures/973c00.stl', $this->filesystem->getAdapter()->getPathPrefix());
|
||||||
|
$this->assertTrue($this->filesystem->has('973c00.png'));
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,11 +2,8 @@
|
|||||||
|
|
||||||
namespace Tests\LoaderBundle\Util\LDModelParser;
|
namespace Tests\LoaderBundle\Util\LDModelParser;
|
||||||
|
|
||||||
use AppBundle\Exception\ErrorParsingLineException;
|
|
||||||
use AppBundle\Exception\ParseErrorException;
|
|
||||||
use LoaderBundle\Util\LDModelParser;
|
use LoaderBundle\Util\LDModelParser;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Validator\Constraints\DateTime;
|
|
||||||
|
|
||||||
class LDModelParserTest extends TestCase
|
class LDModelParserTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -25,31 +22,30 @@ class LDModelParserTest extends TestCase
|
|||||||
$resource = file_get_contents(__DIR__.'/fixtures/valid.dat');
|
$resource = file_get_contents(__DIR__.'/fixtures/valid.dat');
|
||||||
|
|
||||||
$array = [
|
$array = [
|
||||||
"id" => "1234",
|
'id' => '1234',
|
||||||
"name" => "Category Name",
|
'name' => 'Category Name',
|
||||||
"category" => "Category!",
|
'category' => 'Category!',
|
||||||
"keywords" => [
|
'keywords' => [
|
||||||
'keyword1', 'keyword 2', 'keyword3', 'keyword4'
|
'keyword1', 'keyword 2', 'keyword3', 'keyword4',
|
||||||
],
|
],
|
||||||
"author" => "Author [nickname]",
|
'author' => 'Author [nickname]',
|
||||||
"modified" => new \DateTime('2017-04-01'),
|
'modified' => new \DateTime('2017-04-01'),
|
||||||
"type" => "Part",
|
'type' => 'Part',
|
||||||
'subparts' => [
|
'subparts' => [
|
||||||
'submodel' => [
|
'submodel' => [
|
||||||
1 => 2,
|
1 => 2,
|
||||||
16 => 1
|
16 => 1,
|
||||||
]
|
|
||||||
],
|
],
|
||||||
"parent" => null,
|
],
|
||||||
"license" => "Redistributable under CCAL version 2.0",
|
'parent' => null,
|
||||||
|
'license' => 'Redistributable under CCAL version 2.0',
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertEquals($array, $this->parser->parse($resource));
|
$this->assertEquals($array, $this->parser->parse($resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException LoaderBundle\Exception\ErrorParsingLineException
|
* @expectedException \LoaderBundle\Exception\ErrorParsingLineException
|
||||||
*/
|
*/
|
||||||
public function testInvalid()
|
public function testInvalid()
|
||||||
{
|
{
|
||||||
@ -58,7 +54,8 @@ class LDModelParserTest extends TestCase
|
|||||||
$this->parser->parse($resource);
|
$this->parser->parse($resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStickers() {
|
public function testStickers()
|
||||||
|
{
|
||||||
$resource = file_get_contents(__DIR__.'/fixtures/stickers.txt');
|
$resource = file_get_contents(__DIR__.'/fixtures/stickers.txt');
|
||||||
|
|
||||||
foreach (preg_split('/^---DAT/m', $resource) as $dat) {
|
foreach (preg_split('/^---DAT/m', $resource) as $dat) {
|
||||||
@ -66,6 +63,13 @@ class LDModelParserTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testColor()
|
||||||
|
{
|
||||||
|
$resource = file_get_contents(__DIR__.'/fixtures/color.dat');
|
||||||
|
|
||||||
|
$this->assertEquals('3705', $this->parser->parse($resource)['parent']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAlias()
|
public function testAlias()
|
||||||
{
|
{
|
||||||
$resource = file_get_contents(__DIR__.'/fixtures/alias.txt');
|
$resource = file_get_contents(__DIR__.'/fixtures/alias.txt');
|
||||||
|
12
tests/LoaderBundle/Util/LDModelParser/fixtures/color.dat
Normal file
12
tests/LoaderBundle/Util/LDModelParser/fixtures/color.dat
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
0 _Technic Axle 4 Black
|
||||||
|
0 Name: 370526.dat
|
||||||
|
0 Author: Michael Heidemann [mikeheide]
|
||||||
|
0 !LDRAW_ORG Part Physical_Colour UPDATE 2010-03
|
||||||
|
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
|
||||||
|
|
||||||
|
0 BFC CERTIFY CCW
|
||||||
|
|
||||||
|
0 !HISTORY 2010-12-31 [PTadmin] Official Update 2010-03
|
||||||
|
|
||||||
|
1 0 0 0 0 1 0 0 0 1 0 0 0 1 3705.DAT
|
||||||
|
0
|
@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
namespace Tests\LoaderBundle\Util\RelationMapper;
|
namespace Tests\LoaderBundle\Util\RelationMapper;
|
||||||
|
|
||||||
use LoaderBundle\Util\RelationMapper;
|
|
||||||
use Doctrine\Common\Cache\ArrayCache;
|
use Doctrine\Common\Cache\ArrayCache;
|
||||||
|
use LoaderBundle\Util\RelationMapper;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\Config\Resource\FileResource;
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
|
||||||
|
|
||||||
class RelationMapperTest extends TestCase
|
class RelationMapperTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -20,7 +18,7 @@ class RelationMapperTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException LoaderBundle\Exception\RelationMapper\ResourceNotFoundException
|
* @expectedException \LoaderBundle\Exception\RelationMapper\ResourceNotFoundException
|
||||||
*/
|
*/
|
||||||
public function testLoadNonExistingResource()
|
public function testLoadNonExistingResource()
|
||||||
{
|
{
|
||||||
@ -30,7 +28,7 @@ class RelationMapperTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException LoaderBundle\Exception\RelationMapper\InvalidResourceException
|
* @expectedException \LoaderBundle\Exception\RelationMapper\InvalidResourceException
|
||||||
*/
|
*/
|
||||||
public function testLoadInvalidResource()
|
public function testLoadInvalidResource()
|
||||||
{
|
{
|
||||||
@ -38,4 +36,15 @@ class RelationMapperTest extends TestCase
|
|||||||
$resource = __DIR__.'/fixtures/invalid.yml';
|
$resource = __DIR__.'/fixtures/invalid.yml';
|
||||||
$mapper->loadResource($resource, 'resources');
|
$mapper->loadResource($resource, 'resources');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \LoaderBundle\Exception\RelationMapper\InvalidDomainException
|
||||||
|
*/
|
||||||
|
public function testLoadInvalidDomain()
|
||||||
|
{
|
||||||
|
$mapper = new RelationMapper(new ArrayCache());
|
||||||
|
$mapper->loadResource(__DIR__.'/fixtures/resources.yml', 'resources');
|
||||||
|
|
||||||
|
$mapper->find('foo', 'incorect');
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user