Completed
Push — master ( c00bbf...06e52a )
by Pavel
17:08 queued 22s
created

UpdateControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 1
cbo 5
dl 0
loc 37
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testUpdateAction() 0 34 1
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Controller;
4
5
use ScayTrase\Api\Cruds\Tests\WebTestCase;
6
use ScayTrase\Api\Cruds\Tests\Fixtures\Common\Entity\MyEntity;
7
8
class UpdateControllerTest extends WebTestCase
9
{
10
    public function testUpdateAction()
11
    {
12
        $client = self::createClient();
13
        $em     = $this->getEntityManager();
14
15
        $entity = new MyEntity('private-data');
16
        $entity->setPublicApiField('public-data');
17
        $em->persist($entity);
18
        $em->flush();
19
        $em->clear();
20
21
22
        $client->request(
23
            'POST',
24
            '/api/entity/my-entity/update',
25
            [
26
                'identifier' => $entity->getId(),
27
                'data'       => [
28
                    'public_api_field' => 'updated-data',
29
                    'parent'           => $entity->getId(),
30
                ],
31
            ],
32
            [],
33
            ['HTTP_CONTENT_TYPE' => 'application/json']
34
        );
35
        $response = $client->getResponse();
36
37
        self::assertTrue($response->isSuccessful());
38
        $em->clear();
39
        $entity = $em->getRepository(MyEntity::class)->find($entity->getId());
40
        self::assertSame('updated-data', $entity->getPublicApiField());
41
        self::assertSame($entity->getParent(), $entity);
42
        self::assertContains($entity, $entity->getChildren());
43
    }
44
}
45