PartKeepr\ProjectBundle\Tests\ProjectTest::testProjectAttachmentRemoval PHP Method

testProjectAttachmentRemoval() public method

    public function testProjectAttachmentRemoval()
    {
        $client = static::makeClient(true);
        /**
         * @var Project
         */
        $project = $this->fixtures->getReference('project');
        $projectAttachment = new ProjectAttachment();
        $fileService = $this->getContainer()->get('partkeepr_uploadedfile_service');
        $fileService->replaceFromData($projectAttachment, 'BLA', 'test.txt');
        $project->addAttachment($projectAttachment);
        $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($project);
        $project->removeAttachment($projectAttachment);
        $serializedProject = $this->getContainer()->get('serializer')->normalize($project, 'jsonld');
        $iriConverter = $this->getContainer()->get('api.iri_converter');
        $iri = $iriConverter->getIriFromItem($project);
        $client->request('PUT', $iri, [], [], [], json_encode($serializedProject));
        $response = json_decode($client->getResponse()->getContent());
        $this->assertInternalType('array', $response->attachments);
        $this->assertArrayNotHasKey(1, $response->attachments, 'When removing an entry from the ArrayCollection, the array must be resorted!');
        $this->assertEquals(0, count($response->attachments));
    }