diff --git a/src/AppBundle/Entity/Rebrickable/Inventory_Set.php b/src/AppBundle/Entity/Rebrickable/Inventory_Set.php index bb2e67f..e45eb45 100644 --- a/src/AppBundle/Entity/Rebrickable/Inventory_Set.php +++ b/src/AppBundle/Entity/Rebrickable/Inventory_Set.php @@ -33,6 +33,14 @@ class Inventory_Set */ protected $quantity; + /** + * @param int $quantity + */ + public function setQuantity($quantity) + { + $this->quantity = $quantity; + } + /** * Get count. * diff --git a/src/AppBundle/Repository/Rebrickable/InventoryRepository.php b/src/AppBundle/Repository/Rebrickable/InventoryRepository.php index 33a1e9e..464c87a 100644 --- a/src/AppBundle/Repository/Rebrickable/InventoryRepository.php +++ b/src/AppBundle/Repository/Rebrickable/InventoryRepository.php @@ -15,8 +15,8 @@ class InventoryRepository extends BaseRepository ->setParameter('setNumber', $number) ->orderBy('inventory.version', 'DESC') ->setMaxResults(1) - ->select('inventory.id'); + ->select('inventory'); - return $queryBuilder->getQuery()->getOneOrNullResult(Query::HYDRATE_SINGLE_SCALAR); + return $queryBuilder->getQuery()->getOneOrNullResult(); } } diff --git a/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php b/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php index cac0aae..de1f21f 100644 --- a/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php +++ b/src/AppBundle/Repository/Rebrickable/Inventory_PartRepository.php @@ -13,23 +13,19 @@ use Doctrine\ORM\Query\Expr\Join; class Inventory_PartRepository extends BaseRepository { /** - * Finds all inventoty_parts in newest inventory of set. - * - * @param string $number Unique number identifier of set - * @param bool $spare If true - find all spare parts, false - find all regular parts, null - spare and regular parts - * @param bool $model If true - find all parts with model relation, false - find all parts without model relation, null - all parts - * - * @return array + * @param Set $set + * @param null $spare + * @param null $model + * @return \Doctrine\ORM\QueryBuilder */ - public function findAllBySetNumber($number, $spare = null, $model = null) - { - $inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number); + private function getQueryBuilderMatching(Set $set, $spare = null, $model = null) { + $inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($set->getId()); $queryBuilder = $this->createQueryBuilder('inventory_part') ->where('inventory_part.inventory = :inventory') - ->setParameter('inventory', $inventory) - ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part') - ->andWhere('part.category != 17'); + ->setParameter('inventory', $inventory->getId()) + ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part'); + if ($spare !== null) { $queryBuilder @@ -44,6 +40,21 @@ class Inventory_PartRepository extends BaseRepository $queryBuilder->andWhere('part.model IS NULL'); } } + return $queryBuilder; + } + + /** + * Finds all inventoty_parts in newest inventory of set. + * + * @param Set $set + * @param bool $spare If true - find all spare parts, false - find all regular parts, null - spare and regular parts + * @param bool $model If true - find all parts with model relation, false - find all parts without model relation, null - all parts + * + * @return array + */ + public function getAllMatching(Set $set, $spare = null, $model = null) + { + $queryBuilder = $this->getQueryBuilderMatching($set,$spare,$model); return $queryBuilder->getQuery()->getResult(); } @@ -59,28 +70,8 @@ class Inventory_PartRepository extends BaseRepository */ public function getPartCount(Set $set, $spare = null, $model = null) { - $inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($set->getId()); - - $queryBuilder = $this->createQueryBuilder('inventory_part') - ->where('inventory_part.inventory = :inventory') - ->setParameter('inventory', $inventory) - ->join(Part::class, 'part', JOIN::WITH, 'inventory_part.part = part') - ->andWhere('part.category != 17') - ->select('SUM(inventory_part.quantity) as parts'); - - if ($spare !== null) { - $queryBuilder - ->andWhere('inventory_part.spare = :spare') - ->setParameter('spare', $spare); - } - - if ($model !== null) { - if ($model === true) { - $queryBuilder->andWhere('part.model IS NOT NULL'); - } else { - $queryBuilder->andWhere('part.model IS NULL'); - } - } + $queryBuilder = $this->getQueryBuilderMatching($set,$spare,$model); + $queryBuilder->select('SUM(inventory_part.quantity) as parts'); return $queryBuilder->getQuery()->getSingleScalarResult(); } diff --git a/src/AppBundle/Service/SetService.php b/src/AppBundle/Service/SetService.php index 3deda87..0f25392 100644 --- a/src/AppBundle/Service/SetService.php +++ b/src/AppBundle/Service/SetService.php @@ -117,7 +117,7 @@ class SetService { $models = []; - $inventoryParts = $this->inventoryPartRepository->findAllBySetNumber($set->getId(), $spare, true); + $inventoryParts = $this->inventoryPartRepository->getAllMatching($set, $spare, true); /** @var Inventory_Part $inventoryPart */ foreach ($inventoryParts as $inventoryPart) { @@ -136,56 +136,6 @@ class SetService return $models; } - /** - * Get array of all known models in the kit(set). - * [ - * modelNumber => [ - * 'model' => Model, - * 'colors => [ - * colorID => [ - * 'color' => Color, - * 'quantity => int - * ] - * ... - * ] - * ] - * ... - * ]. - * - * @param Set $set - * @param bool $spare If true - add only spare parts, false - add only regular parts, null - add all parts - * - * @return array - */ - public function getModelsWithColors(Set $set, $spare = null) - { - $models = []; - - $inventoryParts = $this->inventoryPartRepository->findAllBySetNumber($set->getId(), $spare, true); - - /** @var Inventory_Part $inventoryPart */ - foreach ($inventoryParts as $inventoryPart) { - if ($model = $inventoryPart->getPart()->getModel()) { - $color = $inventoryPart->getColor(); - - if (!isset($models[$model->getId()]['model'])) { - $models[$model->getId()]['model'] = $model; - } - - if (isset($models[$model->getId()]['colors'][$color->getId()])) { - $models[$model->getId()]['colors'][$color->getId()]['quantity'] += $inventoryPart->getQuantity(); - } else { - $models[$model->getId()]['colors'][$color->getId()] = [ - 'color' => $color, - 'quantity' => $inventoryPart->getQuantity(), - ]; - } - } - } - - return $models; - } - /** * Get array models grouped by color. * [ @@ -211,7 +161,7 @@ class SetService { $colors = []; - $inventoryParts = $this->inventoryPartRepository->findAllBySetNumber($set->getId(), $spare, true); + $inventoryParts = $this->inventoryPartRepository->getAllMatching($set, $spare, true); /** @var Inventory_Part $inventoryPart */ foreach ($inventoryParts as $inventoryPart) { @@ -225,14 +175,10 @@ class SetService $colors[$color->getId()]['quantity'] += $inventoryPart->getQuantity(); - if (isset($colors[$color->getId()]['models'][$model->getId()])) { - $colors[$color->getId()]['models'][$model->getId()]['quantity'] += $inventoryPart->getQuantity(); - } else { - $colors[$color->getId()]['models'][$model->getId()] = [ - 'model' => $model, - 'quantity' => $inventoryPart->getQuantity(), - ]; - } + $colors[$color->getId()]['models'][$model->getId()] = [ + 'model' => $model, + 'quantity' => $inventoryPart->getQuantity(), + ]; } } @@ -249,7 +195,7 @@ class SetService { $parts = []; - $inventoryParts = $this->inventoryPartRepository->findAllBySetNumber($set->getId(), $spare, $model); + $inventoryParts = $this->inventoryPartRepository->getAllMatching($set, $spare, $model); /** @var Inventory_Part $inventoryPart */ foreach ($inventoryParts as $inventoryPart) { diff --git a/src/FrontBundle/Controller/MediaController.php b/src/FrontBundle/Controller/MediaController.php index 627def3..3bd6896 100644 --- a/src/FrontBundle/Controller/MediaController.php +++ b/src/FrontBundle/Controller/MediaController.php @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; /** @@ -36,6 +37,6 @@ class MediaController extends Controller return $response; } - throw new FileNotFoundException($path); + throw new NotFoundHttpException($path); } } diff --git a/src/FrontBundle/Form/Search/ModelSearchType.php b/src/FrontBundle/Form/Search/ModelSearchType.php index 6c1744c..3af7c73 100644 --- a/src/FrontBundle/Form/Search/ModelSearchType.php +++ b/src/FrontBundle/Form/Search/ModelSearchType.php @@ -59,9 +59,4 @@ class ModelSearchType extends AbstractType 'method' => 'GET', ]); } - - public function getName() - { - return 'model_search_type'; - } } diff --git a/src/FrontBundle/Form/Search/SetSearchType.php b/src/FrontBundle/Form/Search/SetSearchType.php index 78a5bf6..9dcf960 100644 --- a/src/FrontBundle/Form/Search/SetSearchType.php +++ b/src/FrontBundle/Form/Search/SetSearchType.php @@ -88,9 +88,4 @@ class SetSearchType extends AbstractType 'method' => 'GET', ]); } - - public function getName() - { - return 'set_search_type'; - } } diff --git a/tests/AppBundle/Fixtures/LoadBaseData.php b/tests/AppBundle/Fixtures/LoadBaseData.php index 4bef18e..80be8fc 100644 --- a/tests/AppBundle/Fixtures/LoadBaseData.php +++ b/tests/AppBundle/Fixtures/LoadBaseData.php @@ -9,6 +9,7 @@ use AppBundle\Entity\LDraw\Model; use AppBundle\Entity\LDraw\Subpart; use AppBundle\Entity\Rebrickable\Inventory; use AppBundle\Entity\Rebrickable\Inventory_Part; +use AppBundle\Entity\Rebrickable\Inventory_Set; use AppBundle\Entity\Rebrickable\Part; use AppBundle\Entity\Rebrickable\Set; use Doctrine\Common\Collections\ArrayCollection; @@ -45,12 +46,12 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface $color2->setTransparent(false); $manager->persist($color2); - $color2 = new Color(); - $color2->setId(-1); - $color2->setName('Unknown'); - $color2->setRgb('EEEEEE'); - $color2->setTransparent(false); - $manager->persist($color2); + $color3 = new Color(); + $color3->setId(-1); + $color3->setName('Unknown'); + $color3->setRgb('EEEEEE'); + $color3->setTransparent(false); + $manager->persist($color3); // Add sample author $author = new Author(); @@ -84,6 +85,15 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface $child2->setPath('models/1.stl'); $manager->persist($child); + // Add sample model + $child3 = new Model(); + $child3->setId(4); + $child3->setAuthor($author); + $child3->setModified(new \DateTime()); + $child3->setName('Name'); + $child3->setPath('models/1.stl'); + $manager->persist($child3); + $subpart = new Subpart(); $subpart->setParent($model); $subpart->setSubpart($child); @@ -97,9 +107,18 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface $subpart2->setCount(2); $subpart2->setColor($color); + $subpart3 = new Subpart(); + $subpart3->setParent($child2); + $subpart3->setSubpart($child3); + $subpart3->setCount(2); + $subpart3->setColor($color); + $model->addSubpart($subpart2); $manager->persist($model); + $child2->addSubpart($subpart3); + $manager->persist($child2); + // Add sample model $alias = new Alias(); $alias->setId('2d'); @@ -120,10 +139,17 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface $manager->persist($part); // Add sample part - $part = new Part(); - $part->setId(2); - $part->setName('Name2'); - $manager->persist($part); + $part2 = new Part(); + $part2->setId(2); + $part2->setName('Name2'); + $part2->setModel($child2); + $manager->persist($part2); + + // Add sample part + $part3 = new Part(); + $part3->setId(3); + $part3->setName('Name3'); + $manager->persist($part3); $set = new Set(); $set->setName('Set name'); @@ -132,21 +158,67 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface $set->setYear(2011); $manager->persist($set); + $set2 = new Set(); + $set2->setName('Set 2'); + $set2->setId('8055-1'); + $set2->setPartCount(2); + $set2->setYear(2015); + $manager->persist($set2); + $inventory = new Inventory(); $inventory->setSet($set); - $inventory->setVersion(1); + $inventory->setVersion(2); $set->addInventory($inventory); $manager->persist($inventory); $manager->persist($set); + $inventory2 = new Inventory(); + $inventory2->setSet($set); + $inventory2->setVersion(1); + $set->addInventory($inventory2); + $manager->persist($inventory2); + $manager->persist($set); + $inventoryPart = new Inventory_Part(); $inventoryPart->setColor($color); - $inventoryPart->setQuantity(5); + $inventoryPart->setQuantity(4); $inventoryPart->setPart($part); $inventoryPart->setInventory($inventory); $inventoryPart->setSpare(false); $manager->persist($inventoryPart); + $inventorySet = new Inventory_Set(); + $inventorySet->setInventory($inventory); + $inventorySet->setSet($set2); + $inventorySet->setQuantity(2); + $manager->persist($inventorySet); + $set->addInventorySet($inventorySet); + $manager->persist($set); + + $inventoryPart = new Inventory_Part(); + $inventoryPart->setColor($color3); + $inventoryPart->setQuantity(6); + $inventoryPart->setPart($part2); + $inventoryPart->setInventory($inventory); + $inventoryPart->setSpare(true); + $manager->persist($inventoryPart); + + $inventoryPart = new Inventory_Part(); + $inventoryPart->setColor($color2); + $inventoryPart->setQuantity(3); + $inventoryPart->setPart($part3); + $inventoryPart->setInventory($inventory); + $inventoryPart->setSpare(false); + $manager->persist($inventoryPart); + + $inventoryPart = new Inventory_Part(); + $inventoryPart->setColor($color); + $inventoryPart->setQuantity(1); + $inventoryPart->setPart($part2); + $inventoryPart->setInventory($inventory); + $inventoryPart->setSpare(false); + $manager->persist($inventoryPart); + $manager->flush(); } } diff --git a/tests/AppBundle/Repository/LDraw/ModelRepositoryTest.php b/tests/AppBundle/Repository/LDraw/ModelRepositoryTest.php index 9625155..de7026f 100644 --- a/tests/AppBundle/Repository/LDraw/ModelRepositoryTest.php +++ b/tests/AppBundle/Repository/LDraw/ModelRepositoryTest.php @@ -48,19 +48,19 @@ class ModelRepositoryTest extends BaseTest public function testCount() { - $this->assertEquals(3, $this->repository->count()); + $this->assertEquals(4, $this->repository->count()); } public function testGetOrCreate() { - $this->assertCount(3, $this->repository->findAll()); + $this->assertCount(4, $this->repository->findAll()); $model = $this->repository->getOrCreate('25'); $this->repository->save($model); - $this->assertCount(3, $this->repository->findAll()); + $this->assertCount(4, $this->repository->findAll()); $model = $this->repository->getOrCreate(33); $this->repository->save($model); - $this->assertCount(4, $this->repository->findAll()); + $this->assertCount(5, $this->repository->findAll()); } } diff --git a/tests/AppBundle/Repository/LDraw/SubpartRepositoryTest.php b/tests/AppBundle/Repository/LDraw/SubpartRepositoryTest.php index 584b914..884741a 100644 --- a/tests/AppBundle/Repository/LDraw/SubpartRepositoryTest.php +++ b/tests/AppBundle/Repository/LDraw/SubpartRepositoryTest.php @@ -23,7 +23,7 @@ class SubpartRepositoryTest extends BaseTest public function testGetOrCreate() { - $this->assertCount(2, $this->repository->findAll()); + $this->assertCount(3, $this->repository->findAll()); /** @var Model $model */ $model = $this->em->getRepository(Model::class)->find(1); @@ -32,14 +32,14 @@ class SubpartRepositoryTest extends BaseTest $subpart = $this->repository->getOrCreate($model, $child, 2, 1); $this->repository->save($subpart); - $this->assertCount(2, $this->repository->findAll()); + $this->assertCount(3, $this->repository->findAll()); $subpart = $this->repository->getOrCreate($model, $child, 2, 2); $this->repository->save($subpart); - $this->assertCount(3, $this->repository->findAll()); + $this->assertCount(4, $this->repository->findAll()); $subpart = $this->repository->getOrCreate($model, $child, 2, 3); $this->repository->save($subpart); - $this->assertCount(4, $this->repository->findAll()); + $this->assertCount(5, $this->repository->findAll()); } } diff --git a/tests/AppBundle/Repository/Rebrickable/InventoryRepositoryTest.php b/tests/AppBundle/Repository/Rebrickable/InventoryRepositoryTest.php new file mode 100644 index 0000000..1c55383 --- /dev/null +++ b/tests/AppBundle/Repository/Rebrickable/InventoryRepositoryTest.php @@ -0,0 +1,28 @@ +setUpDb([LoadBaseData::class]); + + $this->repository = $this->em->getRepository(Inventory::class); + } + + public function testFindNewestInventoryBySetNumber() + { + $this->assertEquals('2',$this->repository->findNewestInventoryBySetNumber('8049-1')->getVersion()); + } +} \ No newline at end of file diff --git a/tests/AppBundle/Repository/Rebrickable/Inventory_PartRepositoryTest.php b/tests/AppBundle/Repository/Rebrickable/Inventory_PartRepositoryTest.php new file mode 100644 index 0000000..4533fb1 --- /dev/null +++ b/tests/AppBundle/Repository/Rebrickable/Inventory_PartRepositoryTest.php @@ -0,0 +1,45 @@ +setUpDb([LoadBaseData::class]); + + $this->repository = $this->em->getRepository(Inventory_Part::class); + } + + public function testAllBySetNumber() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + + $this->assertCount(4,$this->repository->getAllMatching($set)); + $this->assertCount(3,$this->repository->getAllMatching($set,false)); + $this->assertCount(1,$this->repository->getAllMatching($set,true)); + $this->assertCount(3,$this->repository->getAllMatching($set,null,true)); + $this->assertCount(1,$this->repository->getAllMatching($set,null,false)); + } + + public function testGetPartCount() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + + $this->assertEquals(14,$this->repository->getPartCount($set)); + $this->assertEquals(8,$this->repository->getPartCount($set,false)); + $this->assertEquals(6,$this->repository->getPartCount($set,true)); + $this->assertEquals(11,$this->repository->getPartCount($set,null,true)); + $this->assertEquals(3,$this->repository->getPartCount($set,null,false)); + } +} diff --git a/tests/AppBundle/Repository/Rebrickable/Inventory_SetRepositoryTest.php b/tests/AppBundle/Repository/Rebrickable/Inventory_SetRepositoryTest.php new file mode 100644 index 0000000..4b488f0 --- /dev/null +++ b/tests/AppBundle/Repository/Rebrickable/Inventory_SetRepositoryTest.php @@ -0,0 +1,30 @@ +setUpDb([LoadBaseData::class]); + + $this->repository = $this->em->getRepository(Inventory_Set::class); + } + + public function testFindAllBySetNumber() { + $this->assertCount(1,$this->repository->findAllBySetNumber('8049-1')); + $this->assertNull($this->repository->findAllBySetNumber('8055-1')); + } +} diff --git a/tests/AppBundle/Repository/Rebrickable/PartRepositoryTest.php b/tests/AppBundle/Repository/Rebrickable/PartRepositoryTest.php new file mode 100644 index 0000000..9821b28 --- /dev/null +++ b/tests/AppBundle/Repository/Rebrickable/PartRepositoryTest.php @@ -0,0 +1,27 @@ +setUpDb([LoadBaseData::class]); + + $this->repository = $this->em->getRepository(Part::class); + } + + public function testFindAllNotPaired() { + $this->assertCount(1,$this->repository->findAllNotPaired()); + } +} \ No newline at end of file diff --git a/tests/AppBundle/Repository/Rebrickable/SetRepositoryTest.php b/tests/AppBundle/Repository/Rebrickable/SetRepositoryTest.php new file mode 100644 index 0000000..546d846 --- /dev/null +++ b/tests/AppBundle/Repository/Rebrickable/SetRepositoryTest.php @@ -0,0 +1,66 @@ +setUpDb([LoadBaseData::class]); + + $this->repository = $this->em->getRepository(Set::class); + } + + public function testFindAllByPart() + { + /** @var Part $part */ + $part = $this->em->getRepository(Part::class)->find(1); + + $this->assertCount(1,$this->repository->findAllByPart($part)); + } + + public function testFindAllByModel() + { + /** @var Model $model */ + $model = $this->em->getRepository(Model::class)->find(1); + + $this->assertCount(1,$this->repository->findAllByModel($model)); + } + + public function testGetMinPartCount() + { + $this->assertEquals(1,$this->repository->getMinPartCount()); + } + + public function testGetMaxPartCount() + { + $this->assertEquals(2,$this->repository->getMaxPartCount()); + } + + public function testGetMinYear() + { + $this->assertEquals(2011,$this->repository->getMinYear()); + } + + public function testCount() + { + $this->assertEquals(2,$this->repository->count()); + } + + public function testGetMaxYear() + { + $this->assertEquals(2015,$this->repository->getMaxYear()); + } +} \ No newline at end of file diff --git a/tests/AppBundle/Service/ColorServiceTest.php b/tests/AppBundle/Service/ColorServiceTest.php new file mode 100644 index 0000000..bab1e80 --- /dev/null +++ b/tests/AppBundle/Service/ColorServiceTest.php @@ -0,0 +1,36 @@ +loadFixtures([ + LoadBaseData::class, + ]); + + $this->colorService = new ColorService($this->em); + } + + + public function testGetAll() + { + $this->assertCount(3,$this->colorService->getAll()); + } +} \ No newline at end of file diff --git a/tests/AppBundle/Service/ModelServiceTest.php b/tests/AppBundle/Service/ModelServiceTest.php new file mode 100644 index 0000000..21c0966 --- /dev/null +++ b/tests/AppBundle/Service/ModelServiceTest.php @@ -0,0 +1,52 @@ +loadFixtures([ + LoadBaseData::class, + ]); + + $this->modelService = new ModelService($this->em); + } + + public function testGetSiblings() + { + $model = $this->em->getRepository(Model::class)->find(1); + + $this->assertCount(0,$this->modelService->getSiblings($model)); + + $model = $this->em->getRepository(Model::class)->find(2); + + $this->assertCount(1,$this->modelService->getSiblings($model)); + } + + public function testGetSubmodels() + { + $model = $this->em->getRepository(Model::class)->find(1); + + $this->assertCount(2,$this->modelService->getSubmodels($model)); + } + + public function testGetTotalCount() + { + $this->assertEquals(4,$this->modelService->getTotalCount()); + } +} \ No newline at end of file diff --git a/tests/AppBundle/Service/SetServiceTest.php b/tests/AppBundle/Service/SetServiceTest.php new file mode 100644 index 0000000..f86bf7c --- /dev/null +++ b/tests/AppBundle/Service/SetServiceTest.php @@ -0,0 +1,77 @@ +loadFixtures([ + LoadBaseData::class, + ]); + + $this->setService = new SetService($this->em); + } + + public function testGetModels() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + $models = $this->setService->getModels($set); + + $this->assertCount(2, $models); + } + + public function testGetTotalCount() { + $this->assertEquals(2 ,$this->setService->getTotalCount()); + } + + public function testGetPartCount() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + $this->assertEquals(14,$this->setService->getPartCount($set)); + } + + public function testGetAllByModel() { + $model = $this->em->getRepository(Model::class)->find(1); + $this->assertCount(1,$this->setService->getAllByModel($model)); + } + + public function testGetAllByPart() { + $part = $this->em->getRepository(Part::class)->find(1); + $this->assertCount(1,$this->setService->getAllByPart($part)); + } + + public function testGetModelsGroupedByColor() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + + $this->assertCount(2,$this->setService->getModelsGroupedByColor($set)); + } + + public function testGetParts() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + + $this->assertCount(2,$this->setService->getModelsGroupedByColor($set)); + } + + public function testGetAllSubsets() { + /** @var Set $set */ + $set = $this->em->getRepository(Set::class)->find('8049-1'); + + $this->assertCount(1,$this->setService->getAllSubSets($set)); + } +} \ No newline at end of file diff --git a/tests/AppBundle/Service/ZipServiceTest.php b/tests/AppBundle/Service/ZipServiceTest.php index e4a1565..5880d4e 100644 --- a/tests/AppBundle/Service/ZipServiceTest.php +++ b/tests/AppBundle/Service/ZipServiceTest.php @@ -2,6 +2,8 @@ namespace Tests\AppBundle\Service; +use AppBundle\Entity\LDraw\Model; +use AppBundle\Entity\Rebrickable\Set; use AppBundle\Service\ModelService; use AppBundle\Service\SetService; use AppBundle\Service\ZipService; @@ -13,12 +15,6 @@ class ZipServiceTest extends BaseTest /** @var ZipService */ private $zipService; - /** @var ModelService */ - private $modelService; - - /** @var SetService */ - private $setService; - public function setUp() { parent::setUp(); @@ -27,17 +23,14 @@ class ZipServiceTest extends BaseTest LoadBaseData::class, ]); - $this->modelService = new ModelService($this->em); - $this->setService = new SetService($this->em); - $this->filesystem->write('models/1.stl', file_get_contents(__DIR__.'/../Fixtures/models/1.stl')); - $this->zipService = new ZipService($this->filesystem, $this->modelService, $this->setService); + $this->zipService = new ZipService($this->filesystem, new ModelService($this->em), new SetService($this->em)); } public function testModelZip() { - $model = $this->modelService->find(1); + $model = $this->em->getRepository(Model::class)->find(1); $path = $this->zipService->createFromModel($model, 'modelzip'); @@ -46,10 +39,19 @@ class ZipServiceTest extends BaseTest public function testSetZip() { - $set = $this->setService->find('8049-1'); + $set = $this->em->getRepository(Set::class)->find('8049-1'); $path = $this->zipService->createFromSet($set, 'setzip'); $this->assertFileExists($path); } + + public function testSetGroupedByColorZip() + { + $set = $this->em->getRepository(Set::class)->find('8049-1'); + + $path = $this->zipService->createFromSet($set, 'setzip', true); + + $this->assertFileExists($path); + } } diff --git a/tests/FrontBundle/Controller/ApplicationAvailabilityTest.php b/tests/FrontBundle/Controller/ApplicationAvailabilityTest.php index 13901d3..cccc782 100644 --- a/tests/FrontBundle/Controller/ApplicationAvailabilityTest.php +++ b/tests/FrontBundle/Controller/ApplicationAvailabilityTest.php @@ -18,6 +18,28 @@ class ApplicationAvailabilityTest extends BaseControllerTest $this->assertTrue($client->getResponse()->isSuccessful()); } + public function testPageIsUnsuccessful() + { + $client = static::createClient(); + + $client->request('GET', '/files/models/sdad'); + + $this->assertTrue($client->getResponse()->isNotFound()); + } + + + /** + * @dataProvider ajaxUrlProvider + */ + public function testPageIsSuccessfulAjax($url) + { + $client = static::createClient(); + + $client->request('GET', $url, [],[],['HTTP_X-Requested-With' => 'XMLHttpRequest']); + + $this->assertTrue($client->getResponse()->isSuccessful()); + } + public function urlProvider() { return [ @@ -41,6 +63,17 @@ class ApplicationAvailabilityTest extends BaseControllerTest ['/sets/brickset/8540/instructions'], ['/sets/brickset/8540/description'], ['/sets/brickset/8540/images'], + ['/files/models/1.stl'] + ]; + } + + public function ajaxUrlProvider() + { + return [ + ['/sets/brickset/8540/reviews'], + ['/sets/brickset/8540/instructions'], + ['/sets/brickset/8540/description'], + ['/sets/brickset/8540/images'], ]; } } diff --git a/tests/LoaderBundle/Service/ImageLoader/ImageLoaderTest.php b/tests/LoaderBundle/Service/ImageLoader/ImageLoaderTest.php index 58542e0..14956f1 100644 --- a/tests/LoaderBundle/Service/ImageLoader/ImageLoaderTest.php +++ b/tests/LoaderBundle/Service/ImageLoader/ImageLoaderTest.php @@ -52,7 +52,7 @@ class ImageLoaderTest extends BaseTest $stlRenderer = $this->createMock(StlRendererService::class); $stlRenderer->method('render')->willReturn('image'); - $stlRenderer->expects($this->exactly(3))->method('render'); + $stlRenderer->expects($this->exactly(4))->method('render'); $this->imageLoader = new ImageLoader($this->em, $this->get('monolog.logger.event'), $this->filesystem, __DIR__.'/fixtures/', $stlRenderer); $this->imageLoader->setOutput(new NullOutput());