mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 12:50:08 -07:00
Fix tests
This commit is contained in:
parent
d66955d62d
commit
d505926a17
39
tests/AppBundle/ApplicationAvailabilityTest.php
Normal file
39
tests/AppBundle/ApplicationAvailabilityTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\AppBundle;
|
||||||
|
|
||||||
|
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||||
|
|
||||||
|
class ApplicationAvailabilityTest extends BaseTest
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->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')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\AppBundle\Service;
|
namespace Tests\AppBundle;
|
||||||
|
|
||||||
use AppBundle\DataFixtures\ORM\LoadColors;
|
use AppBundle\DataFixtures\ORM\LoadColors;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
use League\Flysystem\FilesystemInterface;
|
use League\Flysystem\FilesystemInterface;
|
||||||
use Liip\FunctionalTestBundle\Test\WebTestCase;
|
use Liip\FunctionalTestBundle\Test\WebTestCase;
|
||||||
@ -17,20 +18,23 @@ abstract class BaseTest extends WebTestCase
|
|||||||
/* @var FilesystemInterface $filesystem */
|
/* @var FilesystemInterface $filesystem */
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
|
|
||||||
|
/** @var EntityManagerInterface */
|
||||||
|
protected $em;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$this->_container = self::$kernel->getContainer();
|
$this->_container = self::$kernel->getContainer();
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->filesystem = $this->get('oneup_flysystem.media_filesystem');
|
$this->filesystem = $this->get('oneup_flysystem.media_filesystem');
|
||||||
|
$this->em = $this->get('doctrine.orm.entity_manager');
|
||||||
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUpDb()
|
public function setUpDb()
|
||||||
{
|
{
|
||||||
// Make sure we are in the test environment
|
// Make sure we are in the test environment
|
||||||
if ('test' !== self::$kernel->getEnvironment()) {
|
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
|
// If you are using the Doctrine Fixtures Bundle you could load these here
|
41
tests/AppBundle/Fixtures/LoadBaseData.php
Normal file
41
tests/AppBundle/Fixtures/LoadBaseData.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\AppBundle\Fixtures;
|
||||||
|
|
||||||
|
|
||||||
|
use AppBundle\Entity\Color;
|
||||||
|
use AppBundle\Entity\LDraw\Author;
|
||||||
|
use AppBundle\Entity\LDraw\Model;
|
||||||
|
use Doctrine\Common\DataFixtures\FixtureInterface;
|
||||||
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
class LoadBaseData implements FixtureInterface, ContainerAwareInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var ContainerInterface
|
||||||
|
*/
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
public function setContainer(ContainerInterface $container = null)
|
||||||
|
{
|
||||||
|
$this->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();
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Tests\AppBundle\Service\Loader\ModelLoader;
|
namespace Tests\AppBundle\Service\Loader\ModelLoader;
|
||||||
|
|
||||||
|
use AppBundle\Entity\LDraw\Alias;
|
||||||
use AppBundle\Entity\LDraw\Model;
|
use AppBundle\Entity\LDraw\Model;
|
||||||
|
use AppBundle\Repository\LDraw\AliasRepository;
|
||||||
use AppBundle\Repository\LDraw\ModelRepository;
|
use AppBundle\Repository\LDraw\ModelRepository;
|
||||||
use AppBundle\Service\Loader\ModelLoader;
|
use AppBundle\Service\Loader\ModelLoader;
|
||||||
use AppBundle\Service\Stl\StlConverterService;
|
use AppBundle\Service\Stl\StlConverterService;
|
||||||
@ -10,7 +12,7 @@ use AppBundle\Util\RelationMapper;
|
|||||||
use League\Flysystem\File;
|
use League\Flysystem\File;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
use Tests\AppBundle\Service\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class ModelLoaderTest extends BaseTest
|
class ModelLoaderTest extends BaseTest
|
||||||
{
|
{
|
||||||
@ -23,10 +25,14 @@ class ModelLoaderTest extends BaseTest
|
|||||||
* @var ModelRepository
|
* @var ModelRepository
|
||||||
*/
|
*/
|
||||||
private $modelRepository;
|
private $modelRepository;
|
||||||
|
|
||||||
|
/** @var AliasRepository */
|
||||||
|
private $aliasRepository;
|
||||||
|
|
||||||
protected function setUp()
|
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 = $this->createMock(File::class);
|
||||||
$file->method('getPath')->willReturn('path');
|
$file->method('getPath')->willReturn('path');
|
||||||
@ -39,8 +45,7 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$relationMapper->method('find')
|
$relationMapper->method('find')
|
||||||
->will($this->returnArgument(0));
|
->will($this->returnArgument(0));
|
||||||
|
|
||||||
$this->modelLoader = new ModelLoader($stlConverter,$relationMapper,null);
|
$this->modelLoader = new ModelLoader($this->get('doctrine.orm.entity_manager'),$this->get('monolog.logger.event'),$stlConverter,$relationMapper,null);
|
||||||
$this->modelLoader->setArguments($this->get('doctrine.orm.entity_manager'),$this->get('monolog.logger.event'),$this->get('app.transformer.format'));
|
|
||||||
$this->modelLoader->setOutput(new NullOutput());
|
$this->modelLoader->setOutput(new NullOutput());
|
||||||
$this->setUpDb();
|
$this->setUpDb();
|
||||||
}
|
}
|
||||||
@ -51,7 +56,7 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$this->modelLoader->loadOne(__DIR__ . '/fixtures/librarycontext/parts/3820.dat');
|
$this->modelLoader->loadOne(__DIR__ . '/fixtures/librarycontext/parts/3820.dat');
|
||||||
|
|
||||||
/** @var Model[] $models */
|
/** @var Model[] $models */
|
||||||
$models = $this->get('repository.ldraw.model')->findAll();
|
$models = $this->modelRepository->findAll();
|
||||||
|
|
||||||
$this->assertEquals(1, count($models));
|
$this->assertEquals(1, count($models));
|
||||||
$this->assertEquals(3820, $models[0]->getId());
|
$this->assertEquals(3820, $models[0]->getId());
|
||||||
@ -64,7 +69,7 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$this->modelLoader->loadOne(__DIR__ . '/fixtures/filecontext/parts/999.dat');
|
$this->modelLoader->loadOne(__DIR__ . '/fixtures/filecontext/parts/999.dat');
|
||||||
|
|
||||||
/** @var Model[] $models */
|
/** @var Model[] $models */
|
||||||
$models = $this->get('repository.ldraw.model')->findAll();
|
$models = $this->modelRepository->findAll();
|
||||||
|
|
||||||
$this->assertEquals(1, count($models));
|
$this->assertEquals(1, count($models));
|
||||||
$this->assertEquals(3820, $models[0]->getId());
|
$this->assertEquals(3820, $models[0]->getId());
|
||||||
@ -136,9 +141,9 @@ class ModelLoaderTest extends BaseTest
|
|||||||
$this->assertEquals(1, count($this->modelRepository->findAll()));
|
$this->assertEquals(1, count($this->modelRepository->findAll()));
|
||||||
$this->assertInstanceOf(Model::class, $model);
|
$this->assertInstanceOf(Model::class, $model);
|
||||||
$this->assertEquals(3, count($model->getAliases()));
|
$this->assertEquals(3, count($model->getAliases()));
|
||||||
$this->assertEquals('3821', $this->get('repository.ldraw.alias')->find('983')->getModel()->getId());
|
$this->assertEquals('3821', $this->aliasRepository->find('983')->getModel()->getId());
|
||||||
$this->assertEquals('3821', $this->get('repository.ldraw.alias')->find('3820')->getModel()->getId());
|
$this->assertEquals('3821', $this->aliasRepository->find('3820')->getModel()->getId());
|
||||||
$this->assertEquals('3821', $this->get('repository.ldraw.alias')->find('500')->getModel()->getId());
|
$this->assertEquals('3821', $this->aliasRepository->find('500')->getModel()->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdate2()
|
public function testUpdate2()
|
||||||
|
@ -6,7 +6,7 @@ use AppBundle\Service\Stl\StlConverterService;
|
|||||||
use AppBundle\Service\Stl\StlFixerService;
|
use AppBundle\Service\Stl\StlFixerService;
|
||||||
use League\Flysystem\Adapter\Local;
|
use League\Flysystem\Adapter\Local;
|
||||||
use League\Flysystem\Filesystem;
|
use League\Flysystem\Filesystem;
|
||||||
use Tests\AppBundle\Service\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class StlConverterTest extends BaseTest
|
class StlConverterTest extends BaseTest
|
||||||
{
|
{
|
||||||
@ -16,20 +16,20 @@ class StlConverterTest extends BaseTest
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$ldview = $this->getParameter('ldview_bin');
|
$ldview = $this->getParameter('ldview_bin');
|
||||||
|
|
||||||
$stlFixer = $this->createMock(StlFixerService::class);
|
$stlFixer = $this->createMock(StlFixerService::class);
|
||||||
$stlFixer->method('fix');
|
$stlFixer->method('fix');
|
||||||
|
|
||||||
$this->stlConverter = new StlConverterService($ldview,$this->filesystem,$stlFixer);
|
$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()
|
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->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'));
|
||||||
@ -42,12 +42,15 @@ class StlConverterTest extends BaseTest
|
|||||||
*/
|
*/
|
||||||
public function testLDContextMissing()
|
public function testLDContextMissing()
|
||||||
{
|
{
|
||||||
$this->stlConverter->setLDrawLibraryContext(null);
|
|
||||||
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
$this->stlConverter->datToStl(__DIR__.'/fixtures/ldraw/parts/983.dat');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConvertToPng()
|
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->assertNotNull($this->stlConverter->datToPng(__DIR__.'/fixtures/ldraw/parts/983.dat'));
|
||||||
|
|
||||||
$this->assertTrue($this->filesystem->has('images/983.png'));
|
$this->assertTrue($this->filesystem->has('images/983.png'));
|
||||||
|
@ -10,7 +10,7 @@ use League\Flysystem\FilesystemInterface;
|
|||||||
use org\bovigo\vfs\vfsStreamDirectory;
|
use org\bovigo\vfs\vfsStreamDirectory;
|
||||||
use org\bovigo\vfs\vfsStreamWrapper;
|
use org\bovigo\vfs\vfsStreamWrapper;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Tests\AppBundle\Service\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class StlFixer extends BaseTest
|
class StlFixer extends BaseTest
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ class StlFixer extends BaseTest
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->stlFixer = $this->get('service.stl.fixer');
|
$this->stlFixer = new StlFixerService($this->getParameter('admesh_bin'));
|
||||||
$this->input = __DIR__.'/fixtures/ascii.stl';
|
$this->input = __DIR__.'/fixtures/ascii.stl';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use League\Flysystem\FilesystemInterface;
|
|||||||
use org\bovigo\vfs\vfsStreamDirectory;
|
use org\bovigo\vfs\vfsStreamDirectory;
|
||||||
use org\bovigo\vfs\vfsStreamWrapper;
|
use org\bovigo\vfs\vfsStreamWrapper;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Tests\AppBundle\Service\BaseTest;
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
class StlRendererTest extends BaseTest
|
class StlRendererTest extends BaseTest
|
||||||
{
|
{
|
||||||
@ -20,7 +20,11 @@ class StlRendererTest extends BaseTest
|
|||||||
|
|
||||||
public function setUp()
|
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()
|
public function tearDown()
|
||||||
|
10
tests/Service/ZipServiceTest.php
Normal file
10
tests/Service/ZipServiceTest.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\AppBundle\Service;
|
||||||
|
|
||||||
|
use Tests\AppBundle\BaseTest;
|
||||||
|
|
||||||
|
class ZipServiceTest extends BaseTest
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user