mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-16 04:10:09 -07:00
Add Rebrickable repository unit tests
This commit is contained in:
parent
d94f15d1d3
commit
871f2ef95b
@ -33,6 +33,14 @@ class Inventory_Set
|
||||
*/
|
||||
protected $quantity;
|
||||
|
||||
/**
|
||||
* @param int $quantity
|
||||
*/
|
||||
public function setQuantity($quantity)
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count.
|
||||
*
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -59,9 +59,4 @@ class ModelSearchType extends AbstractType
|
||||
'method' => 'GET',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'model_search_type';
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +88,4 @@ class SetSearchType extends AbstractType
|
||||
'method' => 'GET',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'set_search_type';
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\Rebrickable;
|
||||
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Repository\Rebrickable\InventoryRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class InventoryRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var InventoryRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Inventory::class);
|
||||
}
|
||||
|
||||
public function testFindNewestInventoryBySetNumber()
|
||||
{
|
||||
$this->assertEquals('2',$this->repository->findNewestInventoryBySetNumber('8049-1')->getVersion());
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\Rebrickable;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\Rebrickable\Inventory_PartRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class Inventory_PartRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var Inventory_PartRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->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));
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\Rebrickable;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Set;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\Rebrickable\Inventory_PartRepository;
|
||||
use AppBundle\Repository\Rebrickable\Inventory_SetRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class Inventory_SetRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var Inventory_SetRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->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'));
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\Rebrickable;
|
||||
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Repository\Rebrickable\PartRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class PartRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var PartRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Part::class);
|
||||
}
|
||||
|
||||
public function testFindAllNotPaired() {
|
||||
$this->assertCount(1,$this->repository->findAllNotPaired());
|
||||
}
|
||||
}
|
66
tests/AppBundle/Repository/Rebrickable/SetRepositoryTest.php
Normal file
66
tests/AppBundle/Repository/Rebrickable/SetRepositoryTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\Rebrickable;
|
||||
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\Rebrickable\SetRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class SetRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var SetRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->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());
|
||||
}
|
||||
}
|
36
tests/AppBundle/Service/ColorServiceTest.php
Normal file
36
tests/AppBundle/Service/ColorServiceTest.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Service;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Service\ColorService;
|
||||
use AppBundle\Service\ModelService;
|
||||
use AppBundle\Service\SetService;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class ColorServiceTest extends BaseTest
|
||||
{
|
||||
/** @var ColorService */
|
||||
private $colorService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->loadFixtures([
|
||||
LoadBaseData::class,
|
||||
]);
|
||||
|
||||
$this->colorService = new ColorService($this->em);
|
||||
}
|
||||
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
$this->assertCount(3,$this->colorService->getAll());
|
||||
}
|
||||
}
|
52
tests/AppBundle/Service/ModelServiceTest.php
Normal file
52
tests/AppBundle/Service/ModelServiceTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Service;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Service\ModelService;
|
||||
use AppBundle\Service\SetService;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class ModelServiceTest extends BaseTest
|
||||
{
|
||||
/** @var ModelService */
|
||||
private $modelService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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());
|
||||
}
|
||||
}
|
77
tests/AppBundle/Service/SetServiceTest.php
Normal file
77
tests/AppBundle/Service/SetServiceTest.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Service;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Service\SetService;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class SetServiceTest extends BaseTest
|
||||
{
|
||||
/** @var SetService */
|
||||
private $setService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user