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 testManufacturerFilter() { /** * @var Part */ $part = $this->fixtures->getReference('part.1'); /** * @var Manufacturer */ $manufacturer = $this->fixtures->getReference('manufacturer.first'); $partManufacturer = new PartManufacturer(); $partManufacturer->setManufacturer($manufacturer); $partManufacturer->setPartNumber('1'); $part->addManufacturer($partManufacturer); $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush(); $filter = ['property' => 'manufacturers.manufacturer', 'operator' => '=', 'value' => $this->getContainer()->get('api.iri_converter')->getIriFromItem($manufacturer)]; $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'}); }
/** * Removes a part manufacturer * * @param PartManufacturer $partManufacturer A part manufacturer to remove */ public function removeManufacturer(PartManufacturer $partManufacturer) { $partManufacturer->setPart(null); $this->manufacturers->removeElement($partManufacturer); }