mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-20 06:00:08 -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 Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use LoaderBundle\Exception\FileNotFoundException;
|
||||
use LoaderBundle\Exception\WriteErrorException;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Asset\Exception\LogicException;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@ -101,27 +99,21 @@ abstract class BaseLoader
|
||||
*
|
||||
* @param $url
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
* @throws WriteErrorException
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
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.');
|
||||
|
||||
$ctx = stream_context_create([], [
|
||||
'notification' => [$this, 'progressCallback'],
|
||||
]);
|
||||
|
||||
try {
|
||||
if (false === file_put_contents($temp, fopen($url, 'r', 0, $ctx))) {
|
||||
throw new WriteErrorException($temp);
|
||||
}
|
||||
} catch (\ErrorException $e) {
|
||||
throw new FileNotFoundException($url);
|
||||
} catch (\Exception $e) {
|
||||
throw new LogicException($e);
|
||||
if (false === file_put_contents($temp, fopen($url, 'r', 0, $ctx))) {
|
||||
throw new WriteErrorException($temp);
|
||||
}
|
||||
|
||||
return $temp;
|
||||
|
@ -5,6 +5,7 @@ namespace LoaderBundle\Service;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use LoaderBundle\Exception\FileException;
|
||||
use LoaderBundle\Service\Stl\StlRendererService;
|
||||
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.
|
||||
*
|
||||
* @param int $color color id used by rebrickable
|
||||
*
|
||||
* @throws FileException
|
||||
*/
|
||||
public function loadColorFromRebrickable($color)
|
||||
{
|
||||
@ -41,14 +44,15 @@ class ImageLoader extends BaseLoader
|
||||
$zip = new \ZipArchive($file);
|
||||
|
||||
if ($zip->open($file) === true) {
|
||||
$this->output->writeln([
|
||||
$this->writeOutput([
|
||||
"Extracting ZIP file into {$this->mediaFilesystem->getAdapter()->getPathPrefix()}images/{$color}",
|
||||
]);
|
||||
$zip->extractTo($this->mediaFilesystem->getAdapter()->getPathPrefix().'images'.DIRECTORY_SEPARATOR.$color);
|
||||
$zip->close();
|
||||
$this->output->writeln(['Done!']);
|
||||
$this->writeOutput(['Done!']);
|
||||
} else {
|
||||
$this->logger->error('Extraction of file failed!');
|
||||
throw new FileException($file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +73,7 @@ class ImageLoader extends BaseLoader
|
||||
unset($models);
|
||||
|
||||
// Render images
|
||||
$this->output->writeln([
|
||||
$this->writeOutput([
|
||||
'Rendering missing images of models',
|
||||
]);
|
||||
$this->initProgressBar(count($missing));
|
||||
@ -79,7 +83,7 @@ class ImageLoader extends BaseLoader
|
||||
try {
|
||||
$this->loadModelImage($this->mediaFilesystem->getAdapter()->getPathPrefix().$model->getPath());
|
||||
} 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();
|
||||
}
|
||||
|
@ -102,27 +102,29 @@ class ModelLoader extends BaseLoader
|
||||
'<fg=cyan>------------------------------------------------------------------------------</>',
|
||||
]);
|
||||
|
||||
$libraryZip = $this->downloadFile($url);
|
||||
try {
|
||||
$libraryZip = $this->downloadFile($url);
|
||||
|
||||
$temp_dir = tempnam(sys_get_temp_dir(), 'printabrick.');
|
||||
if (file_exists($temp_dir)) {
|
||||
unlink($temp_dir);
|
||||
}
|
||||
mkdir($temp_dir);
|
||||
$temp_dir = tempnam(sys_get_temp_dir(), 'printabrick.');
|
||||
if (file_exists($temp_dir)) {
|
||||
unlink($temp_dir);
|
||||
}
|
||||
mkdir($temp_dir);
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($libraryZip) != 'true') {
|
||||
echo 'Error :- Unable to open the Zip File';
|
||||
}
|
||||
$zip->extractTo($temp_dir);
|
||||
$zip->close();
|
||||
unlink($libraryZip);
|
||||
$zip = new \ZipArchive();
|
||||
$zip->open($libraryZip);
|
||||
$zip->extractTo($temp_dir);
|
||||
$zip->close();
|
||||
unlink($libraryZip);
|
||||
|
||||
$this->writeOutput(['<info>LDraw libary downloaded</info>']);
|
||||
$this->writeOutput(['<info>LDraw libary downloaded</info>']);
|
||||
|
||||
// return ldraw directory if in zip file
|
||||
if (file_exists($temp_dir.'/ldraw/')) {
|
||||
return $temp_dir.'/ldraw/';
|
||||
// return ldraw directory if in zip file
|
||||
if (file_exists($temp_dir.'/ldraw/')) {
|
||||
return $temp_dir.'/ldraw/';
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
throw new \LogicException('Falied to open Zip archive');
|
||||
}
|
||||
|
||||
return $temp_dir;
|
||||
|
@ -6,6 +6,7 @@ use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use LoaderBundle\Exception\Loader\LoadingRebrickableFailedException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
//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()
|
||||
{
|
||||
@ -67,19 +68,19 @@ class RebrickableLoader extends BaseLoader
|
||||
|
||||
$this->writeOutput(['Rebrickable database loaded successfully!']);
|
||||
} catch (\Exception $e) {
|
||||
$this->writeOutput(['Rollback back']);
|
||||
$connection->rollBack();
|
||||
throw $e;
|
||||
// $this->writeOutput(['Rollback back']);
|
||||
// $connection->rollBack();
|
||||
|
||||
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()
|
||||
{
|
||||
$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([
|
||||
'<fg=cyan>------------------------------------------------------------------------------</>',
|
||||
@ -133,6 +134,9 @@ class RebrickableLoader extends BaseLoader
|
||||
return $this->em->getConnection()->prepare($query)->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates missing Part entites for foreign keys form inventory_parts table.
|
||||
*/
|
||||
private function addMissingParts()
|
||||
{
|
||||
$connection = $this->em->getConnection();
|
||||
@ -185,8 +189,8 @@ class RebrickableLoader extends BaseLoader
|
||||
return $this->loadCsvFile($csv, 'rebrickable_category', '(`id`,`name`)');
|
||||
}
|
||||
|
||||
private function loadColorTable($csv)
|
||||
{
|
||||
return $this->loadCsvFile($csv, 'color', '(`id`,`name`,`rgb`, @var) SET transparent = IF(@var=\'t\',1,0)');
|
||||
}
|
||||
// private function loadColorTable($csv)
|
||||
// {
|
||||
// return $this->loadCsvFile($csv, 'color', '(`id`,`name`,`rgb`, @var) SET transparent = IF(@var=\'t\',1,0)');
|
||||
// }
|
||||
}
|
||||
|
@ -93,65 +93,9 @@ class StlConverterService
|
||||
|
||||
return $this->mediaFilesystem->get($newFile);
|
||||
}
|
||||
} else {
|
||||
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');
|
||||
return $this->mediaFilesystem->get($newFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ namespace LoaderBundle\Service\Stl;
|
||||
use LoaderBundle\Exception\ConvertingFailedException;
|
||||
use LoaderBundle\Exception\FileNotFoundException;
|
||||
use LoaderBundle\Exception\RenderFailedException;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\ProcessBuilder;
|
||||
|
||||
@ -101,9 +102,6 @@ class StlRendererService
|
||||
if (!file_exists($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
|
||||
// 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
|
||||
//+A0.n - perform antialiasing (if color change is above n percent)
|
||||
//-D - Turns graphic display off
|
||||
$process = $processBuilder->setPrefix($this->povray)
|
||||
$process = $processBuilder
|
||||
->setPrefix($this->povray)
|
||||
->setArguments([
|
||||
"+I\"{$file}\"",
|
||||
'+FN',
|
||||
@ -207,8 +206,13 @@ class StlRendererService
|
||||
'+A0.5',
|
||||
'-D',
|
||||
])->getProcess();
|
||||
|
||||
$process->mustRun();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new ProcessFailedException($process);
|
||||
}
|
||||
|
||||
if (!file_exists($outputFile)) {
|
||||
throw new RenderFailedException("{$to}{$filename}.png");
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
namespace LoaderBundle\Util;
|
||||
|
||||
use Doctrine\Common\Cache\CacheProvider;
|
||||
use LoaderBundle\Exception\RelationMapper\InvalidDomainException;
|
||||
use LoaderBundle\Exception\RelationMapper\InvalidResourceException;
|
||||
use LoaderBundle\Exception\RelationMapper\ResourceNotFoundException;
|
||||
use Symfony\Component\OptionsResolver\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
@ -69,6 +69,6 @@ class RelationMapper
|
||||
if (isset($this->relations[$domain])) {
|
||||
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
|
||||
|
||||
namespace Tests\LoaderBundle\Service\ModelLoader;
|
||||
namespace Tests\LoaderBundle\Service;
|
||||
|
||||
use AppBundle\DataFixtures\ORM\LoadColors;
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Repository\LDraw\AliasRepository;
|
||||
use AppBundle\Repository\LDraw\ModelRepository;
|
||||
use League\Flysystem\File;
|
||||
use LoaderBundle\Service\ModelLoader;
|
||||
use LoaderBundle\Service\Stl\StlConverterService;
|
||||
use LoaderBundle\Util\RelationMapper;
|
||||
use League\Flysystem\File;
|
||||
use League\Flysystem\Filesystem;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
|
||||
@ -47,15 +47,15 @@ class ModelLoaderTest extends BaseTest
|
||||
$relationMapper->method('find')
|
||||
->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->setUpDb();
|
||||
$this->setUpDb([LoadColors::class]);
|
||||
}
|
||||
|
||||
public function testLoadOne()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadOne(__DIR__ . '/fixtures/librarycontext/parts/3820.dat');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadOne(__DIR__.'/fixtures/librarycontext/parts/3820.dat');
|
||||
|
||||
/** @var Model[] $models */
|
||||
$models = $this->modelRepository->findAll();
|
||||
@ -67,33 +67,33 @@ class ModelLoaderTest extends BaseTest
|
||||
|
||||
public function testFileContext()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadOne(__DIR__ . '/fixtures/filecontext/parts/999.dat');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadOne(__DIR__.'/fixtures/filecontext/parts/999.dat');
|
||||
|
||||
/** @var Model[] $models */
|
||||
$models = $this->modelRepository->findAll();
|
||||
|
||||
$this->assertEquals(1, count($models));
|
||||
$this->assertEquals(3820, $models[0]->getId());
|
||||
$this->assertEquals(2,count($models[0]->getAliases()));
|
||||
$this->assertEquals(2, count($models[0]->getAliases()));
|
||||
}
|
||||
|
||||
public function testLoadAlias()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadOne(__DIR__ . '/fixtures/filecontext/parts/999.dat');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadOne(__DIR__.'/fixtures/filecontext/parts/999.dat');
|
||||
|
||||
/** @var Model[] $models */
|
||||
$models = $this->modelRepository->findAll();
|
||||
|
||||
$this->assertEquals(1, count($models));
|
||||
$this->assertEquals(3820, $models[0]->getId());
|
||||
$this->assertEquals(2,count($models[0]->getAliases()));
|
||||
$this->assertEquals(2, count($models[0]->getAliases()));
|
||||
}
|
||||
|
||||
public function testLicense()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/license/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/license/');
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
$models = $this->modelRepository->findAll();
|
||||
@ -104,7 +104,7 @@ class ModelLoaderTest extends BaseTest
|
||||
|
||||
public function testIsIncluded()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/included/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/included/');
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
$models = $this->modelRepository->findAll();
|
||||
@ -113,7 +113,7 @@ class ModelLoaderTest extends BaseTest
|
||||
|
||||
public function testLoadAll()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/librarycontext/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/librarycontext/');
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
$models = $this->modelRepository->findAll();
|
||||
@ -124,17 +124,17 @@ class ModelLoaderTest extends BaseTest
|
||||
public function testUpdate()
|
||||
{
|
||||
// Load original model
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/update/version1/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/update/version1/');
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
$this->assertEquals(1, count($this->modelRepository->findAll()));
|
||||
$model = $this->modelRepository->findOneByNumber('983');
|
||||
$this->assertInstanceOf(Model::class, $model);
|
||||
$this->assertEquals('3820',$model->getId());
|
||||
$this->assertEquals('3820', $model->getId());
|
||||
$this->assertEquals(2, count($model->getAliases()));
|
||||
|
||||
// Load new version
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/update/version2/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/update/version2/');
|
||||
$this->modelLoader->setRewrite(true);
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
@ -151,31 +151,49 @@ class ModelLoaderTest extends BaseTest
|
||||
public function testUpdate2()
|
||||
{
|
||||
// Load original model
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/update2/version1/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/update2/version1/');
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
// Load new version
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/update2/version2/');
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/update2/version2/');
|
||||
$this->modelLoader->setRewrite(false);
|
||||
$this->modelLoader->loadAll();
|
||||
|
||||
/** @var Model $model */
|
||||
$model = $this->modelRepository->find('3820');
|
||||
$this->assertEquals(1, count($this->modelRepository->findAll()));
|
||||
$this->assertEquals(2009,$model->getModified()->format('Y'));
|
||||
$this->assertEquals(2009, $model->getModified()->format('Y'));
|
||||
|
||||
$this->modelLoader->setRewrite(true);
|
||||
$this->modelLoader->loadAll();
|
||||
$this->assertEquals(2010,$model->getModified()->format('Y'));
|
||||
$this->assertEquals(2010, $model->getModified()->format('Y'));
|
||||
}
|
||||
|
||||
public function testLoadOfPrinted() {
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__ . '/fixtures/printed/');
|
||||
$this->modelLoader->loadOne(__DIR__ . '/fixtures/printed/parts/30367bps7.dat');
|
||||
public function testLoadOfPrinted()
|
||||
{
|
||||
$this->modelLoader->setLDrawLibraryContext(__DIR__.'/fixtures/printed/');
|
||||
$this->modelLoader->loadOne(__DIR__.'/fixtures/printed/parts/30367bps7.dat');
|
||||
|
||||
$models = $this->modelRepository->findAll();
|
||||
|
||||
$this->assertEquals(1, count($models));
|
||||
$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;
|
||||
|
||||
use LoaderBundle\Service\Stl\StlConverterService;
|
||||
use LoaderBundle\Service\Stl\StlFixerService;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\Filesystem;
|
||||
use LoaderBundle\Service\Stl\StlConverterService;
|
||||
use LoaderBundle\Service\Stl\StlFixerService;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
|
||||
class StlConverterTest extends BaseTest
|
||||
@ -13,7 +13,6 @@ class StlConverterTest extends BaseTest
|
||||
/** @var StlConverterService */
|
||||
private $stlConverter;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@ -23,40 +22,70 @@ class StlConverterTest extends BaseTest
|
||||
$stlFixer = $this->createMock(StlFixerService::class);
|
||||
$stlFixer->method('fix');
|
||||
|
||||
$this->stlConverter = new StlConverterService($ldview,$this->filesystem,$stlFixer);
|
||||
$this->stlConverter = new StlConverterService($ldview, $this->filesystem, $stlFixer);
|
||||
}
|
||||
|
||||
public function testConvertToStl()
|
||||
{
|
||||
$adapter = new Local(__DIR__ . '/fixtures/ldraw');
|
||||
$adapter = new Local(__DIR__.'/fixtures/ldraw');
|
||||
$ldrawLibraryContext = new Filesystem($adapter);
|
||||
$this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext);
|
||||
|
||||
$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->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()
|
||||
{
|
||||
$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()
|
||||
{
|
||||
$adapter = new Local(__DIR__ . '/fixtures/ldraw');
|
||||
$stlFixer = $this->createMock(StlFixerService::class);
|
||||
$stlFixer->method('fix');
|
||||
|
||||
$this->stlConverter = new StlConverterService('', $this->filesystem, $stlFixer);
|
||||
|
||||
$adapter = new Local(__DIR__.'/fixtures/ldraw');
|
||||
$ldrawLibraryContext = new Filesystem($adapter);
|
||||
$this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext);
|
||||
|
||||
$this->assertNotNull($this->stlConverter->datToPng(__DIR__ . '/fixtures/ldraw/parts/983.dat'));
|
||||
|
||||
$this->assertTrue($this->filesystem->has('images/983.png'));
|
||||
|
||||
$this->filesystem->delete('images/983.png');
|
||||
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
||||
}
|
||||
}
|
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;
|
||||
|
||||
use LoaderBundle\Service\Stl\StlConverterService;
|
||||
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;
|
||||
|
||||
class StlFixer extends BaseTest
|
||||
@ -22,18 +17,30 @@ class StlFixer extends BaseTest
|
||||
parent::setUp();
|
||||
|
||||
$this->stlFixer = new StlFixerService($this->getParameter('admesh_bin'));
|
||||
$this->input = __DIR__ . '/fixtures/ascii.stl';
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->filesystem->delete('output.stl');
|
||||
$this->input = __DIR__.'/fixtures/ascii.stl';
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
use LoaderBundle\Service\Stl\StlConverterService;
|
||||
use LoaderBundle\Service\Stl\StlFixerService;
|
||||
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;
|
||||
|
||||
class StlRendererTest extends BaseTest
|
||||
@ -20,21 +14,37 @@ class StlRendererTest extends BaseTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$layout = __DIR__ . '/fixtures/layout.tmpl';
|
||||
$layout = __DIR__.'/fixtures/layout.tmpl';
|
||||
$povray = $this->getParameter('povray_bin');
|
||||
$stl2pov = $this->getParameter('stl2pov_bin');
|
||||
|
||||
$this->stlRenderer = new StlRendererService($layout,$povray,$stl2pov);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->filesystem->delete('973c00.png');
|
||||
$this->stlRenderer = new StlRendererService($layout, $povray, $stl2pov);
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
use AppBundle\Exception\ErrorParsingLineException;
|
||||
use AppBundle\Exception\ParseErrorException;
|
||||
use LoaderBundle\Util\LDModelParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Constraints\DateTime;
|
||||
|
||||
class LDModelParserTest extends TestCase
|
||||
{
|
||||
@ -22,53 +19,60 @@ class LDModelParserTest extends TestCase
|
||||
|
||||
public function testValid()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__ . '/fixtures/valid.dat');
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/valid.dat');
|
||||
|
||||
$array = [
|
||||
"id" => "1234",
|
||||
"name" => "Category Name",
|
||||
"category" => "Category!",
|
||||
"keywords" => [
|
||||
'keyword1', 'keyword 2', 'keyword3', 'keyword4'
|
||||
'id' => '1234',
|
||||
'name' => 'Category Name',
|
||||
'category' => 'Category!',
|
||||
'keywords' => [
|
||||
'keyword1', 'keyword 2', 'keyword3', 'keyword4',
|
||||
],
|
||||
"author" => "Author [nickname]",
|
||||
"modified" => new \DateTime('2017-04-01'),
|
||||
"type" => "Part",
|
||||
'author' => 'Author [nickname]',
|
||||
'modified' => new \DateTime('2017-04-01'),
|
||||
'type' => 'Part',
|
||||
'subparts' => [
|
||||
'submodel' => [
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException LoaderBundle\Exception\ErrorParsingLineException
|
||||
* @expectedException \LoaderBundle\Exception\ErrorParsingLineException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__ . '/fixtures/invalid.dat');
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/invalid.dat');
|
||||
|
||||
$this->parser->parse($resource);
|
||||
}
|
||||
|
||||
public function testStickers() {
|
||||
$resource = file_get_contents(__DIR__ . '/fixtures/stickers.txt');
|
||||
public function testStickers()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/stickers.txt');
|
||||
|
||||
foreach (preg_split('/^---DAT/m', $resource) as $dat) {
|
||||
$this->assertEquals('Sticker', $this->parser->parse($dat)['type']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testColor()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/color.dat');
|
||||
|
||||
$this->assertEquals('3705', $this->parser->parse($resource)['parent']);
|
||||
}
|
||||
|
||||
public function testAlias()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__ . '/fixtures/alias.txt');
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/alias.txt');
|
||||
|
||||
foreach (preg_split('/^---DAT/m', $resource) as $dat) {
|
||||
$this->assertEquals('parent', $this->parser->parse($dat)['parent']);
|
||||
|
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,25 +2,23 @@
|
||||
|
||||
namespace Tests\LoaderBundle\Util\RelationMapper;
|
||||
|
||||
use LoaderBundle\Util\RelationMapper;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use LoaderBundle\Util\RelationMapper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class RelationMapperTest extends TestCase
|
||||
{
|
||||
public function testLoad()
|
||||
{
|
||||
$mapper = new RelationMapper(new ArrayCache());
|
||||
$mapper->loadResource(__DIR__ . '/fixtures/resources.yml', 'resources');
|
||||
$mapper->loadResource(__DIR__.'/fixtures/resources.yml', 'resources');
|
||||
|
||||
$this->assertEquals('bar', $mapper->find('foo','resources'));
|
||||
$this->assertEquals('bar', $mapper->find('bar','resources'));
|
||||
$this->assertEquals('bar', $mapper->find('foo', 'resources'));
|
||||
$this->assertEquals('bar', $mapper->find('bar', 'resources'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LoaderBundle\Exception\RelationMapper\ResourceNotFoundException
|
||||
* @expectedException \LoaderBundle\Exception\RelationMapper\ResourceNotFoundException
|
||||
*/
|
||||
public function testLoadNonExistingResource()
|
||||
{
|
||||
@ -30,12 +28,23 @@ class RelationMapperTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException LoaderBundle\Exception\RelationMapper\InvalidResourceException
|
||||
* @expectedException \LoaderBundle\Exception\RelationMapper\InvalidResourceException
|
||||
*/
|
||||
public function testLoadInvalidResource()
|
||||
{
|
||||
$mapper = new RelationMapper(new ArrayCache());
|
||||
$resource = __DIR__ . '/fixtures/invalid.yml';
|
||||
$resource = __DIR__.'/fixtures/invalid.yml';
|
||||
$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