PartTest.php (4291B)
1 <?php 2 3 namespace PartKeepr\PartBundle\Tests; 4 5 use Doctrine\Common\DataFixtures\ProxyReferenceRepository; 6 use Liip\FunctionalTestBundle\Test\WebTestCase; 7 use PartKeepr\PartBundle\Entity\Part; 8 use PartKeepr\PartBundle\Entity\PartAttachment; 9 use PartKeepr\PartBundle\Entity\PartDistributor; 10 use PartKeepr\PartBundle\Entity\PartManufacturer; 11 12 class PartTest extends WebTestCase 13 { 14 /** 15 * @var ProxyReferenceRepository 16 */ 17 protected $fixtures; 18 19 public function setUp() 20 { 21 $this->fixtures = $this->loadFixtures( 22 [ 23 'PartKeepr\StorageLocationBundle\DataFixtures\CategoryDataLoader', 24 'PartKeepr\StorageLocationBundle\DataFixtures\StorageLocationLoader', 25 'PartKeepr\PartBundle\DataFixtures\CategoryDataLoader', 26 'PartKeepr\PartBundle\DataFixtures\PartDataLoader', 27 'PartKeepr\ManufacturerBundle\Tests\DataFixtures\ManufacturerDataLoader', 28 'PartKeepr\DistributorBundle\Tests\DataFixtures\DistributorDataLoader', 29 ] 30 )->getReferenceRepository(); 31 } 32 33 /** 34 * @expectedException PartKeepr\PartBundle\Exceptions\CategoryNotAssignedException 35 */ 36 public function testCategoryRequired() 37 { 38 $part = new Part(); 39 $part->setName('TEST'); 40 $part->setStorageLocation($this->fixtures->getReference('storagelocation.first')); 41 42 $this->getContainer()->get('doctrine.orm.default_entity_manager')->persist($part); 43 $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($part); 44 } 45 46 /** 47 * @expectedException PartKeepr\PartBundle\Exceptions\StorageLocationNotAssignedException 48 */ 49 public function testStorageLocationRequired() 50 { 51 $part = new Part(); 52 $part->setName('TEST'); 53 $part->setCategory($this->getContainer()->get('partkeepr.part.category_service')->getRootNode()); 54 55 $this->getContainer()->get('doctrine.orm.default_entity_manager')->persist($part); 56 $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($part); 57 } 58 59 public function testBasics() 60 { 61 $part = new Part(); 62 $part->setName('TEST'); 63 $part->setCategory($this->getContainer()->get('partkeepr.part.category_service')->getRootNode()); 64 $part->setStorageLocation($this->fixtures->getReference('storagelocation.first')); 65 66 $this->getContainer()->get('doctrine.orm.default_entity_manager')->persist($part); 67 $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($part); 68 } 69 70 public function testAssociationRemoval() 71 { 72 $part = new Part(); 73 $part->setName('TEST'); 74 $part->setCategory($this->getContainer()->get('partkeepr.part.category_service')->getRootNode()); 75 $part->setStorageLocation($this->fixtures->getReference('storagelocation.first')); 76 77 $partManufacturer = new PartManufacturer(); 78 $partManufacturer->setManufacturer($this->fixtures->getReference('manufacturer.first')); 79 $part->addManufacturer($partManufacturer); 80 81 $partDistributor = new PartDistributor(); 82 $partDistributor->setDistributor($this->fixtures->getReference('distributor.first')); 83 $part->addDistributor($partDistributor); 84 85 $partAttachment = new PartAttachment(); 86 87 $fileService = $this->getContainer()->get('partkeepr_uploadedfile_service'); 88 $fileService->replaceFromData($partAttachment, 'BLA', 'test.txt'); 89 90 $part->addAttachment($partAttachment); 91 92 $this->getContainer()->get('doctrine.orm.default_entity_manager')->persist($part); 93 $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($part); 94 95 $part->removeDistributor($partDistributor); 96 $part->removeManufacturer($partManufacturer); 97 $part->removeAttachment($partAttachment); 98 99 $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($part); 100 101 $storage = $fileService->getStorage($partAttachment); 102 103 $this->assertNull($partDistributor->getId()); 104 $this->assertNull($partDistributor->getId()); 105 $this->assertNull($partAttachment->getId()); 106 $this->assertFalse($storage->has($partAttachment->getFullFilename())); 107 } 108 }