mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-16 12:20:09 -07:00
Add AppBundle tests
This commit is contained in:
parent
f2899fcf17
commit
709e069f02
@ -23,6 +23,8 @@
|
||||
<directory>src</directory>
|
||||
<exclude>
|
||||
<directory>src/*Bundle/Resources</directory>
|
||||
<directory>src/*Bundle/Api/Client</directory>
|
||||
<directory>src/*Bundle/DataFixtures</directory>
|
||||
<directory>src/*/*Bundle/Resources</directory>
|
||||
<directory>src/*/Bundle/*Bundle/Resources</directory>
|
||||
</exclude>
|
||||
|
@ -111,6 +111,8 @@ class BricksetClient
|
||||
return null;
|
||||
} catch (\SoapFault $e) {
|
||||
throw new CallFailedException(ApiException::BRICKSET);
|
||||
} catch (AuthenticationFailedException $e) {
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
throw new ApiException(ApiException::BRICKSET);
|
||||
}
|
||||
|
@ -150,11 +150,11 @@ class Set
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $inventorySets
|
||||
* @param Inventory_Set $inventorySet
|
||||
*/
|
||||
public function setInventorySets($inventorySets)
|
||||
public function addInventorySet($inventorySet)
|
||||
{
|
||||
$this->inventorySets = $inventorySets;
|
||||
$this->inventorySets->add($inventorySet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,4 +92,14 @@ class Theme
|
||||
|
||||
return implode(' > ', array_reverse($name));
|
||||
}
|
||||
|
||||
public function getGroup()
|
||||
{
|
||||
$theme = $this;
|
||||
while (($theme->getParent()) !== null) {
|
||||
$theme = $theme->getParent();
|
||||
}
|
||||
|
||||
return $theme;
|
||||
}
|
||||
}
|
||||
|
@ -2,25 +2,6 @@
|
||||
|
||||
namespace AppBundle\Repository;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class ColorRepository extends BaseRepository
|
||||
{
|
||||
public function findAllBySet(Set $set)
|
||||
{
|
||||
$inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($set->getId());
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('color');
|
||||
|
||||
$queryBuilder
|
||||
->join(Inventory_Part::class, 'inventory_part', Join::WITH, 'inventory_part.color = color.id')
|
||||
->where('inventory_part.inventory = :inventory')
|
||||
->setParameter('inventory', $inventory)
|
||||
->distinct(true);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
@ -3,36 +3,20 @@
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Category;
|
||||
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\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class ModelRepository extends BaseRepository
|
||||
{
|
||||
public function getFilteredQueryBuilder()
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model')
|
||||
->where('model.name NOT LIKE :obsolete')
|
||||
->setParameter('obsolete', '~%');
|
||||
|
||||
return $queryBuilder;
|
||||
}
|
||||
|
||||
public function findAllByCategory($category)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model')
|
||||
->join(Category::class, 'type', Join::LEFT_JOIN, 'model.category = :category')
|
||||
->setParameter('category', $category);
|
||||
|
||||
return $queryBuilder->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find model by id or alias id.
|
||||
*
|
||||
* @param $number
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findOneByNumber($number)
|
||||
{
|
||||
$model = $this->createQueryBuilder('model')
|
||||
@ -56,40 +40,7 @@ class ModelRepository extends BaseRepository
|
||||
return $this->findOneBy(['name' => $name]);
|
||||
}
|
||||
|
||||
public function findAllRegularBySetNumber($number)
|
||||
{
|
||||
$inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number);
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('model');
|
||||
|
||||
$queryBuilder
|
||||
->join(Part::class, 'part', JOIN::WITH, 'part.model = model')
|
||||
->join(Inventory_Part::class, 'inventory_part', JOIN::WITH, 'part.id = inventory_part.part')
|
||||
->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = :inventory')
|
||||
->setParameter('inventory', $inventory)
|
||||
->addSelect('inventory_part')
|
||||
->distinct(true);
|
||||
|
||||
return $queryBuilder->getQuery()->getScalarResult();
|
||||
}
|
||||
|
||||
public function findAllBySetNumber($number)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model');
|
||||
|
||||
$queryBuilder
|
||||
->join(Part::class, 'part', JOIN::WITH, 'part.model = model')
|
||||
->join(Inventory_Part::class, 'inventory_part', JOIN::WITH, 'part.id = inventory_part.part')
|
||||
->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory.id')
|
||||
->join(Set::class, 's', Join::WITH, 'inventory.set = s.id')
|
||||
->where('s.id LIKE :number')
|
||||
->setParameter('number', $number)
|
||||
->distinct(true);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findAllRelatedModels(Model $model)
|
||||
public function findAllSiblings(Model $model)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model');
|
||||
|
||||
@ -123,7 +74,7 @@ class ModelRepository extends BaseRepository
|
||||
*/
|
||||
public function getOrCreate($id)
|
||||
{
|
||||
if (($model = $this->findOneBy(['id' => $id])) == null) {
|
||||
if (($model = $this->findOneByNumber($id)) == null) {
|
||||
$model = new Model();
|
||||
$model->setId($id);
|
||||
}
|
||||
|
@ -8,11 +8,6 @@ use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class SubpartRepository extends BaseRepository
|
||||
{
|
||||
public function findOneByKeys($parent, $child, $color)
|
||||
{
|
||||
return $this->find(['parent' => $parent, 'subpart' => $child, 'color' => $color]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Subpart relation entity or retrieve one by foreign keys.
|
||||
*
|
||||
@ -25,7 +20,7 @@ class SubpartRepository extends BaseRepository
|
||||
*/
|
||||
public function getOrCreate($parent, $child, $count, $colorId)
|
||||
{
|
||||
if (($subpart = $this->findOneByKeys($parent, $child, $colorId))) {
|
||||
if (($subpart = $this->find(['parent' => $parent, 'subpart' => $child, 'color' => $colorId]))) {
|
||||
$subpart->setCount($count);
|
||||
} else {
|
||||
$subpart = new Subpart();
|
||||
|
@ -48,27 +48,6 @@ class Inventory_PartRepository extends BaseRepository
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all Inventory_Parts with $color in set.
|
||||
*
|
||||
* @param string $number
|
||||
* @param int $color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findAllBySetNumberAndColor($number, $color)
|
||||
{
|
||||
$inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number);
|
||||
|
||||
$queryBuilder = $this->createQueryBuilder('inventory_part')
|
||||
->where('inventory_part.inventory = :inventory')
|
||||
->setParameter('inventory', $inventory)
|
||||
->andWhere('inventory_part.color = :color')
|
||||
->setParameter('color', $color);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total part count of Set.
|
||||
*
|
||||
|
@ -4,46 +4,16 @@ namespace AppBundle\Repository\Rebrickable;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Category;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class PartRepository extends BaseRepository
|
||||
{
|
||||
public function findAllByModel(Model $model)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('part');
|
||||
|
||||
$queryBuilder
|
||||
->where('part.model = :model')
|
||||
->setParameter('model', $model);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findAllNotPaired()
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('part')
|
||||
->leftJoin(Category::class, 'category', JOIN::WITH, 'part.category = category.id')
|
||||
->where('category.name NOT LIKE :categoryName')
|
||||
->andWhere('part.model IS NULL')
|
||||
->setParameter('categoryName', 'Non-LEGO')
|
||||
->distinct(true);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findAllBySetNumber($number)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('part');
|
||||
|
||||
$inventory = $this->getEntityManager()->getRepository(Inventory::class)->findNewestInventoryBySetNumber($number);
|
||||
|
||||
$queryBuilder
|
||||
->join(Inventory_Part::class, 'inventory_part', JOIN::WITH, 'part.number = inventory_part.part')
|
||||
->where('inventory_part.inventory = :inventory')
|
||||
->setParameter('inventory', $inventory)
|
||||
->where('part.model IS NULL')
|
||||
->distinct(true);
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
|
@ -13,16 +13,6 @@ use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class SetRepository extends BaseRepository
|
||||
{
|
||||
public function findAllByTheme(Theme $theme)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('s')
|
||||
->join(Theme::class, 'theme', Join::WITH, 's.theme = theme')
|
||||
->where('theme.id = :id')
|
||||
->setParameter('id', $theme->getId());
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findAllByPart(Part $part)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('s')
|
||||
|
@ -2,26 +2,8 @@
|
||||
|
||||
namespace AppBundle\Repository\Rebrickable;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Theme;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class ThemeRepository extends BaseRepository
|
||||
{
|
||||
public function findAllSubthemes(Theme $theme)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('theme')
|
||||
->where('theme.parent = :id')
|
||||
->setParameter('id', $theme->getId());
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findAllMain()
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('theme')
|
||||
->where('theme.parent IS NULL')
|
||||
->orderBy('theme.name', 'ASC');
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class ModelService
|
||||
*/
|
||||
public function getSiblings(Model $model)
|
||||
{
|
||||
return $this->modelRepository->findAllRelatedModels($model);
|
||||
return $this->modelRepository->findAllSiblings($model);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,14 +2,9 @@
|
||||
|
||||
namespace Tests\AppBundle;
|
||||
|
||||
use AppBundle\DataFixtures\ORM\LoadColors;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use Liip\FunctionalTestBundle\Test\WebTestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
abstract class BaseTest extends WebTestCase
|
||||
{
|
||||
@ -25,7 +20,7 @@ abstract class BaseTest extends WebTestCase
|
||||
$this->em = $this->get('doctrine.orm.entity_manager');
|
||||
}
|
||||
|
||||
public function setUpDb()
|
||||
public function setUpDb(array $fixtures)
|
||||
{
|
||||
// Make sure we are in the test environment
|
||||
if ('test' !== $this->get('kernel')->getEnvironment()) {
|
||||
@ -33,9 +28,7 @@ abstract class BaseTest extends WebTestCase
|
||||
}
|
||||
|
||||
// If you are using the Doctrine Fixtures Bundle you could load these here
|
||||
$this->loadFixtures([
|
||||
LoadColors::class
|
||||
]);
|
||||
$this->loadFixtures($fixtures);
|
||||
}
|
||||
|
||||
protected function get($service)
|
||||
@ -47,4 +40,15 @@ abstract class BaseTest extends WebTestCase
|
||||
{
|
||||
return $this->getContainer()->getParameter($parameter);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->filesystem->deleteDir('models');
|
||||
$this->filesystem->deleteDir('images');
|
||||
|
||||
$this->em->close();
|
||||
$this->em = null; // avoid memory leaks
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,15 @@
|
||||
namespace Tests\AppBundle\Fixtures;
|
||||
|
||||
use AppBundle\Entity\Color;
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Author;
|
||||
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\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\DataFixtures\FixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
@ -28,6 +31,27 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$color = new Color();
|
||||
$color->setId(1);
|
||||
$color->setName('Black');
|
||||
$color->setRgb('000000');
|
||||
$color->setTransparent(false);
|
||||
$manager->persist($color);
|
||||
|
||||
$color2 = new Color();
|
||||
$color2->setId(2);
|
||||
$color2->setName('Blue');
|
||||
$color2->setRgb('EEEEEE');
|
||||
$color2->setTransparent(false);
|
||||
$manager->persist($color2);
|
||||
|
||||
$color2 = new Color();
|
||||
$color2->setId(-1);
|
||||
$color2->setName('Unknown');
|
||||
$color2->setRgb('EEEEEE');
|
||||
$color2->setTransparent(false);
|
||||
$manager->persist($color2);
|
||||
|
||||
// Add sample author
|
||||
$author = new Author();
|
||||
$author->setName('Author');
|
||||
@ -42,6 +66,52 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface
|
||||
$model->setPath('models/1.stl');
|
||||
$manager->persist($model);
|
||||
|
||||
// Add sample model
|
||||
$child = new Model();
|
||||
$child->setId(2);
|
||||
$child->setAuthor($author);
|
||||
$child->setModified(new \DateTime());
|
||||
$child->setName('Name2');
|
||||
$child->setPath('models/1.stl');
|
||||
$manager->persist($child);
|
||||
|
||||
// Add sample model
|
||||
$child2 = new Model();
|
||||
$child2->setId(3);
|
||||
$child2->setAuthor($author);
|
||||
$child2->setModified(new \DateTime());
|
||||
$child2->setName('Name2');
|
||||
$child2->setPath('models/1.stl');
|
||||
$manager->persist($child);
|
||||
|
||||
$subpart = new Subpart();
|
||||
$subpart->setParent($model);
|
||||
$subpart->setSubpart($child);
|
||||
$subpart->setCount(2);
|
||||
$subpart->setColor($color);
|
||||
$model->addSubpart($subpart);
|
||||
|
||||
$subpart2 = new Subpart();
|
||||
$subpart2->setParent($model);
|
||||
$subpart2->setSubpart($child2);
|
||||
$subpart2->setCount(2);
|
||||
$subpart2->setColor($color);
|
||||
|
||||
$model->addSubpart($subpart2);
|
||||
$manager->persist($model);
|
||||
|
||||
// Add sample model
|
||||
$alias = new Alias();
|
||||
$alias->setId('2d');
|
||||
$alias->setModel($model);
|
||||
$manager->persist($alias);
|
||||
|
||||
// Add sample model
|
||||
$alias = new Alias();
|
||||
$alias->setId('25');
|
||||
$alias->setModel($model);
|
||||
$manager->persist($alias);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId(1);
|
||||
@ -49,24 +119,25 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface
|
||||
$part->setModel($model);
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId(2);
|
||||
$part->setName('Name2');
|
||||
$manager->persist($part);
|
||||
|
||||
$set = new Set();
|
||||
$set->setName('Set');
|
||||
$set->setName('Set name');
|
||||
$set->setId('8049-1');
|
||||
$set->setPartCount(1);
|
||||
$set->setYear(2011);
|
||||
$manager->persist($set);
|
||||
|
||||
$color = new Color();
|
||||
$color->setId(1);
|
||||
$color->setName('Black');
|
||||
$color->setRgb('000000');
|
||||
$color->setTransparent(false);
|
||||
$manager->persist($color);
|
||||
|
||||
$inventory = new Inventory();
|
||||
$inventory->setSet($set);
|
||||
$inventory->setVersion(1);
|
||||
$set->addInventory($inventory);
|
||||
$manager->persist($inventory);
|
||||
$manager->persist($set);
|
||||
|
||||
$inventoryPart = new Inventory_Part();
|
||||
$inventoryPart->setColor($color);
|
||||
@ -78,4 +149,4 @@ class LoadBaseData implements FixtureInterface, ContainerAwareInterface
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
135
tests/AppBundle/Fixtures/LoadUnmappedData.php
Normal file
135
tests/AppBundle/Fixtures/LoadUnmappedData.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Fixtures;
|
||||
|
||||
use AppBundle\Entity\Color;
|
||||
use AppBundle\Entity\LDraw\Author;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use Doctrine\Common\DataFixtures\FixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
class LoadUnmappedData implements FixtureInterface
|
||||
{
|
||||
// /**
|
||||
// * @var ContainerInterface
|
||||
// */
|
||||
// private $container;
|
||||
//
|
||||
// public function setContainer(ContainerInterface $container = null)
|
||||
// {
|
||||
// $this->container = $container;
|
||||
// }
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
// Add sample author
|
||||
$author = new Author();
|
||||
$author->setName('Author');
|
||||
$manager->persist($author);
|
||||
|
||||
// Add sample model
|
||||
$model = new Model();
|
||||
$model->setId('930');
|
||||
$model->setAuthor($author);
|
||||
$model->setModified(new \DateTime());
|
||||
$model->setName('Name');
|
||||
$model->setPath('models/1.stl');
|
||||
$manager->persist($model);
|
||||
|
||||
// Add sample model
|
||||
$model = new Model();
|
||||
$model->setId('973c00');
|
||||
$model->setAuthor($author);
|
||||
$model->setModified(new \DateTime());
|
||||
$model->setName('ModelName');
|
||||
$model->setPath('models/1.stl');
|
||||
$manager->persist($model);
|
||||
|
||||
// Add sample model
|
||||
$model = new Model();
|
||||
$model->setId('970c00');
|
||||
$model->setAuthor($author);
|
||||
$model->setModified(new \DateTime());
|
||||
$model->setName('Name 3');
|
||||
$model->setPath('models/1.stl');
|
||||
$manager->persist($model);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('930');
|
||||
$part->setName('Name');
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('930p01');
|
||||
$part->setName('Part2');
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('930pr002');
|
||||
$part->setName('Part2');
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('930pb001a');
|
||||
$part->setName('Part2');
|
||||
$part->setModel($model);
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('973c05');
|
||||
$part->setName('Part2');
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('1235');
|
||||
$part->setName('ModelName');
|
||||
$manager->persist($part);
|
||||
|
||||
// Add sample part
|
||||
$part = new Part();
|
||||
$part->setId('970c52');
|
||||
$part->setName('part');
|
||||
$manager->persist($part);
|
||||
|
||||
$set = new Set();
|
||||
$set->setName('Set');
|
||||
$set->setId('8049-1');
|
||||
$set->setPartCount(1);
|
||||
$set->setYear(2011);
|
||||
$manager->persist($set);
|
||||
|
||||
$color = new Color();
|
||||
$color->setId(1);
|
||||
$color->setName('Black');
|
||||
$color->setRgb('000000');
|
||||
$color->setTransparent(false);
|
||||
$manager->persist($color);
|
||||
|
||||
$inventory = new Inventory();
|
||||
$inventory->setSet($set);
|
||||
$inventory->setVersion(1);
|
||||
$manager->persist($inventory);
|
||||
|
||||
$inventoryPart = new Inventory_Part();
|
||||
$inventoryPart->setColor($color);
|
||||
$inventoryPart->setQuantity(5);
|
||||
$inventoryPart->setPart($part);
|
||||
$inventoryPart->setInventory($inventory);
|
||||
$inventoryPart->setSpare(false);
|
||||
$manager->persist($inventoryPart);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
39
tests/AppBundle/Repository/LDraw/AliasRepositoryTest.php
Normal file
39
tests/AppBundle/Repository/LDraw/AliasRepositoryTest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Repository\LDraw\AliasRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class AliasRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var AliasRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Alias::class);
|
||||
}
|
||||
|
||||
public function testGetOrCreate()
|
||||
{
|
||||
$this->assertCount(2, $this->repository->findAll());
|
||||
|
||||
/** @var Model $model */
|
||||
$model = $this->em->getRepository(Model::class)->find(1);
|
||||
|
||||
$alias = $this->repository->getOrCreate(25, $model);
|
||||
$this->repository->save($alias);
|
||||
$this->assertCount(2, $this->repository->findAll());
|
||||
|
||||
$alias = $this->repository->getOrCreate(33, $model);
|
||||
$this->repository->save($alias);
|
||||
$this->assertCount(3, $this->repository->findAll());
|
||||
}
|
||||
}
|
35
tests/AppBundle/Repository/LDraw/AuthorRepositoryTest.php
Normal file
35
tests/AppBundle/Repository/LDraw/AuthorRepositoryTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Author;
|
||||
use AppBundle\Repository\LDraw\AuthorRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class AuthorRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var AuthorRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Author::class);
|
||||
}
|
||||
|
||||
public function testGetOrCreate()
|
||||
{
|
||||
$this->assertCount(1, $this->repository->findAll());
|
||||
|
||||
$author = $this->repository->getOrCreate('Author');
|
||||
$this->repository->save($author);
|
||||
$this->assertCount(1, $this->repository->findAll());
|
||||
|
||||
$author = $this->repository->getOrCreate('Author2');
|
||||
$this->repository->save($author);
|
||||
$this->assertCount(2, $this->repository->findAll());
|
||||
}
|
||||
}
|
35
tests/AppBundle/Repository/LDraw/CategoryRepositoryTest.php
Normal file
35
tests/AppBundle/Repository/LDraw/CategoryRepositoryTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Category;
|
||||
use AppBundle\Repository\LDraw\CategoryRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class CategoryRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var CategoryRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Category::class);
|
||||
}
|
||||
|
||||
public function testGetOrCreate()
|
||||
{
|
||||
$this->assertCount(0, $this->repository->findAll());
|
||||
|
||||
$category = $this->repository->getOrCreate('Category');
|
||||
$this->repository->save($category);
|
||||
$this->assertCount(1, $this->repository->findAll());
|
||||
|
||||
$category = $this->repository->getOrCreate('Category');
|
||||
$this->repository->save($category);
|
||||
$this->assertCount(1, $this->repository->findAll());
|
||||
}
|
||||
}
|
35
tests/AppBundle/Repository/LDraw/KeywordRepositoryTest.php
Normal file
35
tests/AppBundle/Repository/LDraw/KeywordRepositoryTest.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Keyword;
|
||||
use AppBundle\Repository\LDraw\KeywordRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class KeywordRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var KeywordRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Keyword::class);
|
||||
}
|
||||
|
||||
public function testGetOrCreate()
|
||||
{
|
||||
$this->assertCount(0, $this->repository->findAll());
|
||||
|
||||
$keyword = $this->repository->getOrCreate('Keyword');
|
||||
$this->repository->save($keyword);
|
||||
$this->assertCount(1, $this->repository->findAll());
|
||||
|
||||
$keyword = $this->repository->getOrCreate('Keyword');
|
||||
$this->repository->save($keyword);
|
||||
$this->assertCount(1, $this->repository->findAll());
|
||||
}
|
||||
}
|
66
tests/AppBundle/Repository/LDraw/ModelRepositoryTest.php
Normal file
66
tests/AppBundle/Repository/LDraw/ModelRepositoryTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Repository\LDraw\ModelRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class ModelRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var ModelRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Model::class);
|
||||
}
|
||||
|
||||
public function testFindOneByNumber()
|
||||
{
|
||||
$model = $this->repository->findOneByNumber('25');
|
||||
$this->assertEquals(1, $model->getId());
|
||||
|
||||
$model = $this->repository->findOneByNumber(1);
|
||||
$this->assertEquals(1, $model->getId());
|
||||
}
|
||||
|
||||
public function testFindOneByName()
|
||||
{
|
||||
$model = $this->repository->findOneByName('Name');
|
||||
$this->assertEquals(1, $model->getId());
|
||||
|
||||
$model = $this->repository->findOneByName('Not');
|
||||
$this->assertNull($model);
|
||||
}
|
||||
|
||||
public function testFindAllSiblings()
|
||||
{
|
||||
$model = $this->repository->findOneByNumber(2);
|
||||
$siblings = $this->repository->findAllSiblings($model);
|
||||
|
||||
$this->assertCount(1, $siblings);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$this->assertEquals(3, $this->repository->count());
|
||||
}
|
||||
|
||||
public function testGetOrCreate()
|
||||
{
|
||||
$this->assertCount(3, $this->repository->findAll());
|
||||
|
||||
$model = $this->repository->getOrCreate('25');
|
||||
$this->repository->save($model);
|
||||
$this->assertCount(3, $this->repository->findAll());
|
||||
|
||||
$model = $this->repository->getOrCreate(33);
|
||||
$this->repository->save($model);
|
||||
$this->assertCount(4, $this->repository->findAll());
|
||||
}
|
||||
}
|
45
tests/AppBundle/Repository/LDraw/SubpartRepositoryTest.php
Normal file
45
tests/AppBundle/Repository/LDraw/SubpartRepositoryTest.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\LDraw\Subpart;
|
||||
use AppBundle\Repository\LDraw\SubpartRepository;
|
||||
use Tests\AppBundle\BaseTest;
|
||||
use Tests\AppBundle\Fixtures\LoadBaseData;
|
||||
|
||||
class SubpartRepositoryTest extends BaseTest
|
||||
{
|
||||
/** @var SubpartRepository */
|
||||
private $repository;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setUpDb([LoadBaseData::class]);
|
||||
|
||||
$this->repository = $this->em->getRepository(Subpart::class);
|
||||
}
|
||||
|
||||
public function testGetOrCreate()
|
||||
{
|
||||
$this->assertCount(2, $this->repository->findAll());
|
||||
|
||||
/** @var Model $model */
|
||||
$model = $this->em->getRepository(Model::class)->find(1);
|
||||
/** @var Model $child */
|
||||
$child = $this->em->getRepository(Model::class)->find(2);
|
||||
|
||||
$subpart = $this->repository->getOrCreate($model, $child, 2, 1);
|
||||
$this->repository->save($subpart);
|
||||
$this->assertCount(2, $this->repository->findAll());
|
||||
|
||||
$subpart = $this->repository->getOrCreate($model, $child, 2, 2);
|
||||
$this->repository->save($subpart);
|
||||
$this->assertCount(3, $this->repository->findAll());
|
||||
|
||||
$subpart = $this->repository->getOrCreate($model, $child, 2, 3);
|
||||
$this->repository->save($subpart);
|
||||
$this->assertCount(4, $this->repository->findAll());
|
||||
}
|
||||
}
|
@ -24,20 +24,15 @@ class ZipServiceTest extends BaseTest
|
||||
parent::setUp();
|
||||
|
||||
$this->loadFixtures([
|
||||
LoadBaseData::class
|
||||
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->filesystem->write('models/1.stl', file_get_contents(__DIR__.'/../Fixtures/models/1.stl'));
|
||||
|
||||
$this->zipService = new ZipService($this->filesystem,$this->modelService,$this->setService);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->filesystem->delete('models/1.stl');
|
||||
$this->zipService = new ZipService($this->filesystem, $this->modelService, $this->setService);
|
||||
}
|
||||
|
||||
public function testModelZip()
|
||||
@ -57,4 +52,4 @@ class ZipServiceTest extends BaseTest
|
||||
|
||||
$this->assertFileExists($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,13 @@ class FormatTransformerTest extends TestCase
|
||||
$this->transformer = new FormatTransformer();
|
||||
}
|
||||
|
||||
public function testBytesToSize() {
|
||||
$this->assertEquals('1.5 MB', $this->transformer->bytesToSize(512*1024+1024*1024, 2));
|
||||
public function testBytesToSize()
|
||||
{
|
||||
$this->assertEquals('1.5 MB', $this->transformer->bytesToSize(512 * 1024 + 1024 * 1024, 2));
|
||||
$this->assertEquals('512 B', $this->transformer->bytesToSize(512, 2));
|
||||
$this->assertEquals('1 KB', $this->transformer->bytesToSize(1024, 2));
|
||||
$this->assertEquals('1 MB', $this->transformer->bytesToSize(1024*1024, 2));
|
||||
$this->assertEquals('1 GB', $this->transformer->bytesToSize(1024*1024*1024, 2));
|
||||
$this->assertEquals('1 TB', $this->transformer->bytesToSize(1024*1024*1024*1024, 2));
|
||||
$this->assertEquals('1 MB', $this->transformer->bytesToSize(1024 * 1024, 2));
|
||||
$this->assertEquals('1 GB', $this->transformer->bytesToSize(1024 * 1024 * 1024, 2));
|
||||
$this->assertEquals('1 TB', $this->transformer->bytesToSize(1024 * 1024 * 1024 * 1024, 2));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user