PartKeepr\PartBundle\Tests\PartTest::testAssociationRemoval PHP Method

testAssociationRemoval() public method

    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()));
    }