Inheritance: extends PartKeepr\CoreBundle\Entity\BaseEntity
Exemple #1
0
 public function testAssociationRemoval()
 {
     $part = new Part();
     $part->setName("TEST");
     $part->setCategory($this->getContainer()->get("partkeepr.part.category_service")->getRootNode());
     $part->setStorageLocation($this->fixtures->getReference("storagelocation.first"));
     $partManufacturer = new PartManufacturer();
     $partManufacturer->setManufacturer($this->fixtures->getReference("manufacturer.first"));
     $part->addManufacturer($partManufacturer);
     $partDistributor = new PartDistributor();
     $partDistributor->setDistributor($this->fixtures->getReference("distributor.first"));
     $part->addDistributor($partDistributor);
     $partAttachment = new PartAttachment();
     $fileService = $this->getContainer()->get("partkeepr_uploadedfile_service");
     $fileService->replaceFromData($partAttachment, "BLA", "test.txt");
     $part->addAttachment($partAttachment);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->persist($part);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($part);
     $part->removeDistributor($partDistributor);
     $part->removeManufacturer($partManufacturer);
     $part->removeAttachment($partAttachment);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($part);
     $storage = $fileService->getStorage($partAttachment);
     $this->assertNull($partDistributor->getId());
     $this->assertNull($partDistributor->getId());
     $this->assertNull($partAttachment->getId());
     $this->assertFalse($storage->has($partAttachment->getFullFilename()));
 }
 public function testDistributorFilter()
 {
     /**
      * @var Part
      */
     $part = $this->fixtures->getReference('part.1');
     /**
      * @var Distributor
      */
     $distributor = $this->fixtures->getReference('distributor.first');
     $partDistributor = new PartDistributor();
     $partDistributor->setDistributor($distributor);
     $part->addDistributor($partDistributor);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush();
     $filter = ['property' => 'distributors.distributor', 'operator' => '=', 'value' => $this->getContainer()->get('api.iri_converter')->getIriFromItem($distributor)];
     $filters = [$filter];
     $client = static::makeClient(true);
     $partResource = $this->getContainer()->get('resource.part');
     $iri = $this->getContainer()->get('api.iri_converter')->getIriFromResource($partResource);
     $client->request('GET', $iri, ['filter' => json_encode($filters)]);
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $data = json_decode($client->getResponse()->getContent());
     $this->assertEquals(1, $data->{'hydra:totalItems'});
 }
Exemple #3
0
 /**
  * Removes a part distributor
  *
  * @param PartDistributor $partDistributor A part distributor to remove
  */
 public function removeDistributor(PartDistributor $partDistributor)
 {
     $partDistributor->setPart(null);
     $this->distributors->removeElement($partDistributor);
 }