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

testCreateProject() public method

public testCreateProject ( )
    public function testCreateProject()
    {
        $client = static::makeClient(true);
        $file = __DIR__ . '/../../UploadedFileBundle/Tests/Fixtures/files/uploadtest.png';
        $originalFilename = 'uploadtest.png';
        $mimeType = 'image/png';
        $image = new UploadedFile($file, $originalFilename, $mimeType, filesize($file));
        $client->request('POST', '/api/temp_uploaded_files/upload', [], ['userfile' => $image]);
        $uploadedFile = json_decode($client->getResponse()->getContent());
        /**
         * @var Part
         */
        $part = $this->fixtures->getReference('part.1');
        $part2 = $this->fixtures->getReference('part.2');
        $serializedPart1 = $this->getContainer()->get('serializer')->normalize($part, 'jsonld');
        $serializedPart2 = $this->getContainer()->get('serializer')->normalize($part2, 'jsonld');
        $project = ['name' => 'foobar', 'description' => 'testdescription', 'attachments' => [$uploadedFile->image], 'parts' => [['quantity' => 1, 'part' => $serializedPart1, 'remarks' => 'testremark'], ['quantity' => 2, 'part' => $serializedPart2, 'remarks' => 'testremark2']]];
        $client->request('POST', '/api/projects', [], [], [], json_encode($project));
        $response = json_decode($client->getResponse()->getContent());
        $this->assertObjectHasAttribute('@type', $response);
        $this->assertEquals('Project', $response->{'@type'});
        $this->assertObjectHasAttribute('name', $response);
        $this->assertEquals('foobar', $response->name);
        $this->assertObjectHasAttribute('description', $response);
        $this->assertEquals('testdescription', $response->description);
        $this->assertObjectHasAttribute('parts', $response);
        $this->assertInternalType('array', $response->parts);
        $this->assertEquals(2, count($response->parts));
        $this->assertArrayHasKey(0, $response->parts);
        $this->assertEquals('ProjectPart', $response->parts[0]->{'@type'});
        $this->assertEquals(1, $response->parts[0]->quantity);
        $this->assertEquals('testremark', $response->parts[0]->remarks);
        $this->assertEquals('Part', $response->parts[0]->part->{'@type'});
        $this->assertObjectHasAttribute('attachments', $response);
        $this->assertEquals(1, count($response->attachments));
        $this->assertArrayHasKey(0, $response->attachments);
        $this->assertEquals('ProjectAttachment', $response->attachments[0]->{'@type'});
        unset($response->parts[0]);
    }