From d505926a172e706967631520fd028e14760c2024 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 7 Jun 2017 17:22:10 +0200 Subject: [PATCH] Fix tests --- .../AppBundle/ApplicationAvailabilityTest.php | 39 ++++++++++++++++++ tests/{Service => AppBundle}/BaseTest.php | 12 ++++-- tests/AppBundle/Fixtures/LoadBaseData.php | 41 +++++++++++++++++++ .../Loader/ModelLoader/ModelLoaderTest.php | 23 +++++++---- .../Stl/StlConverter/StlConverterTest.php | 17 ++++---- tests/Service/Stl/StlFixer/StlFixerTest.php | 4 +- .../Stl/StlRenderer/StlRendererTest.php | 8 +++- tests/Service/ZipServiceTest.php | 10 +++++ 8 files changed, 130 insertions(+), 24 deletions(-) create mode 100644 tests/AppBundle/ApplicationAvailabilityTest.php rename tests/{Service => AppBundle}/BaseTest.php (81%) create mode 100644 tests/AppBundle/Fixtures/LoadBaseData.php create mode 100644 tests/Service/ZipServiceTest.php diff --git a/tests/AppBundle/ApplicationAvailabilityTest.php b/tests/AppBundle/ApplicationAvailabilityTest.php new file mode 100644 index 0000000..1c72420 --- /dev/null +++ b/tests/AppBundle/ApplicationAvailabilityTest.php @@ -0,0 +1,39 @@ +setUpDb(); + + $this->loadFixtures([ + LoadBaseData::class + ]); + + parent::setUp(); + } + + /** + * @dataProvider urlProvider + */ + public function testPageIsSuccessful($url) + { + $client = $this->makeClient(); + $client->request('GET', $url); + + $this->assertTrue( $client->getResponse()->isSuccessful()); + } + + public function urlProvider() + { + return array( + array('/'), + array('/models') + ); + } +} \ No newline at end of file diff --git a/tests/Service/BaseTest.php b/tests/AppBundle/BaseTest.php similarity index 81% rename from tests/Service/BaseTest.php rename to tests/AppBundle/BaseTest.php index 1b36b54..fc13e8c 100644 --- a/tests/Service/BaseTest.php +++ b/tests/AppBundle/BaseTest.php @@ -1,9 +1,10 @@ _container = self::$kernel->getContainer(); - parent::__construct(); - $this->filesystem = $this->get('oneup_flysystem.media_filesystem'); + $this->em = $this->get('doctrine.orm.entity_manager'); + parent::__construct(); } public function setUpDb() { // Make sure we are in the test environment if ('test' !== self::$kernel->getEnvironment()) { - throw new \LogicException('Primer must be executed in the test environment'); + throw new \LogicException('setUpDb must be executed in the test environment'); } // If you are using the Doctrine Fixtures Bundle you could load these here diff --git a/tests/AppBundle/Fixtures/LoadBaseData.php b/tests/AppBundle/Fixtures/LoadBaseData.php new file mode 100644 index 0000000..95b3188 --- /dev/null +++ b/tests/AppBundle/Fixtures/LoadBaseData.php @@ -0,0 +1,41 @@ +container = $container; + } + + public function load(ObjectManager $manager) + { + $author = new Author(); + $author->setName('Author'); + + $model = new Model(); + $model->setId(1); + $model->setAuthor($author); + $model->setModified(new \DateTime()); + $model->setName('Name'); + + $manager->persist($model); + + $manager->flush(); + } +} \ No newline at end of file diff --git a/tests/Service/Loader/ModelLoader/ModelLoaderTest.php b/tests/Service/Loader/ModelLoader/ModelLoaderTest.php index 0c4af1e..f5f73e7 100644 --- a/tests/Service/Loader/ModelLoader/ModelLoaderTest.php +++ b/tests/Service/Loader/ModelLoader/ModelLoaderTest.php @@ -2,7 +2,9 @@ namespace Tests\AppBundle\Service\Loader\ModelLoader; +use AppBundle\Entity\LDraw\Alias; use AppBundle\Entity\LDraw\Model; +use AppBundle\Repository\LDraw\AliasRepository; use AppBundle\Repository\LDraw\ModelRepository; use AppBundle\Service\Loader\ModelLoader; use AppBundle\Service\Stl\StlConverterService; @@ -10,7 +12,7 @@ use AppBundle\Util\RelationMapper; use League\Flysystem\File; use League\Flysystem\Filesystem; use Symfony\Component\Console\Output\NullOutput; -use Tests\AppBundle\Service\BaseTest; +use Tests\AppBundle\BaseTest; class ModelLoaderTest extends BaseTest { @@ -23,10 +25,14 @@ class ModelLoaderTest extends BaseTest * @var ModelRepository */ private $modelRepository; + + /** @var AliasRepository */ + private $aliasRepository; protected function setUp() { - $this->modelRepository = $this->get('repository.ldraw.model'); + $this->modelRepository = $this->em->getRepository(Model::class); + $this->aliasRepository = $this->em->getRepository(Alias::class); $file = $this->createMock(File::class); $file->method('getPath')->willReturn('path'); @@ -39,8 +45,7 @@ class ModelLoaderTest extends BaseTest $relationMapper->method('find') ->will($this->returnArgument(0)); - $this->modelLoader = new ModelLoader($stlConverter,$relationMapper,null); - $this->modelLoader->setArguments($this->get('doctrine.orm.entity_manager'),$this->get('monolog.logger.event'),$this->get('app.transformer.format')); + $this->modelLoader = new ModelLoader($this->get('doctrine.orm.entity_manager'),$this->get('monolog.logger.event'),$stlConverter,$relationMapper,null); $this->modelLoader->setOutput(new NullOutput()); $this->setUpDb(); } @@ -51,7 +56,7 @@ class ModelLoaderTest extends BaseTest $this->modelLoader->loadOne(__DIR__ . '/fixtures/librarycontext/parts/3820.dat'); /** @var Model[] $models */ - $models = $this->get('repository.ldraw.model')->findAll(); + $models = $this->modelRepository->findAll(); $this->assertEquals(1, count($models)); $this->assertEquals(3820, $models[0]->getId()); @@ -64,7 +69,7 @@ class ModelLoaderTest extends BaseTest $this->modelLoader->loadOne(__DIR__ . '/fixtures/filecontext/parts/999.dat'); /** @var Model[] $models */ - $models = $this->get('repository.ldraw.model')->findAll(); + $models = $this->modelRepository->findAll(); $this->assertEquals(1, count($models)); $this->assertEquals(3820, $models[0]->getId()); @@ -136,9 +141,9 @@ class ModelLoaderTest extends BaseTest $this->assertEquals(1, count($this->modelRepository->findAll())); $this->assertInstanceOf(Model::class, $model); $this->assertEquals(3, count($model->getAliases())); - $this->assertEquals('3821', $this->get('repository.ldraw.alias')->find('983')->getModel()->getId()); - $this->assertEquals('3821', $this->get('repository.ldraw.alias')->find('3820')->getModel()->getId()); - $this->assertEquals('3821', $this->get('repository.ldraw.alias')->find('500')->getModel()->getId()); + $this->assertEquals('3821', $this->aliasRepository->find('983')->getModel()->getId()); + $this->assertEquals('3821', $this->aliasRepository->find('3820')->getModel()->getId()); + $this->assertEquals('3821', $this->aliasRepository->find('500')->getModel()->getId()); } public function testUpdate2() diff --git a/tests/Service/Stl/StlConverter/StlConverterTest.php b/tests/Service/Stl/StlConverter/StlConverterTest.php index 0e24aed..de17d0b 100644 --- a/tests/Service/Stl/StlConverter/StlConverterTest.php +++ b/tests/Service/Stl/StlConverter/StlConverterTest.php @@ -6,7 +6,7 @@ use AppBundle\Service\Stl\StlConverterService; use AppBundle\Service\Stl\StlFixerService; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; -use Tests\AppBundle\Service\BaseTest; +use Tests\AppBundle\BaseTest; class StlConverterTest extends BaseTest { @@ -16,20 +16,20 @@ class StlConverterTest extends BaseTest public function setUp() { - $ldview = $this->getParameter('ldview_bin'); + $ldview = $this->getParameter('ldview_bin'); $stlFixer = $this->createMock(StlFixerService::class); $stlFixer->method('fix'); $this->stlConverter = new StlConverterService($ldview,$this->filesystem,$stlFixer); - - $adapter = new Local(__DIR__.'/fixtures/ldraw'); - $ldrawLibraryContext = new Filesystem($adapter); - $this->stlConverter->setLDrawLibraryContext($ldrawLibraryContext); } public function testConvertToStl() { + $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->assertTrue($this->filesystem->has('models/983.stl')); @@ -42,12 +42,15 @@ class StlConverterTest extends BaseTest */ public function testLDContextMissing() { - $this->stlConverter->setLDrawLibraryContext(null); $this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat'); } public function testConvertToPng() { + $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')); diff --git a/tests/Service/Stl/StlFixer/StlFixerTest.php b/tests/Service/Stl/StlFixer/StlFixerTest.php index 0ed990f..80b2982 100644 --- a/tests/Service/Stl/StlFixer/StlFixerTest.php +++ b/tests/Service/Stl/StlFixer/StlFixerTest.php @@ -10,7 +10,7 @@ use League\Flysystem\FilesystemInterface; use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamWrapper; use PHPUnit\Framework\TestCase; -use Tests\AppBundle\Service\BaseTest; +use Tests\AppBundle\BaseTest; class StlFixer extends BaseTest { @@ -21,7 +21,7 @@ class StlFixer extends BaseTest public function setUp() { - $this->stlFixer = $this->get('service.stl.fixer'); + $this->stlFixer = new StlFixerService($this->getParameter('admesh_bin')); $this->input = __DIR__.'/fixtures/ascii.stl'; } diff --git a/tests/Service/Stl/StlRenderer/StlRendererTest.php b/tests/Service/Stl/StlRenderer/StlRendererTest.php index c55c41e..d02a05e 100644 --- a/tests/Service/Stl/StlRenderer/StlRendererTest.php +++ b/tests/Service/Stl/StlRenderer/StlRendererTest.php @@ -11,7 +11,7 @@ use League\Flysystem\FilesystemInterface; use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamWrapper; use PHPUnit\Framework\TestCase; -use Tests\AppBundle\Service\BaseTest; +use Tests\AppBundle\BaseTest; class StlRendererTest extends BaseTest { @@ -20,7 +20,11 @@ class StlRendererTest extends BaseTest public function setUp() { - $this->stlRenderer = $this->get('service.stl.renderer'); + $layout = $this->get('kernel')->getRootDir().'/Resources/povray_layout/layout.tmpl'; + $povray = $this->getParameter('povray_bin'); + $stl2pov = $this->getParameter('stl2pov_bin'); + + $this->stlRenderer = new StlRendererService($layout,$povray,$stl2pov); } public function tearDown() diff --git a/tests/Service/ZipServiceTest.php b/tests/Service/ZipServiceTest.php new file mode 100644 index 0000000..83de053 --- /dev/null +++ b/tests/Service/ZipServiceTest.php @@ -0,0 +1,10 @@ +