Completed
Push — master ( 0f15f1...06dce9 )
by Pavel
09:44
created

CountControllerTest::testCountWithRelation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 23

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
dl 34
loc 34
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 1
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Controller;
4
5
use ScayTrase\Api\Cruds\Tests\AbstractCrudsWebTest;
6
use ScayTrase\Api\Cruds\Tests\Fixtures\Common\Entity\MyEntity;
7
8
class CountControllerTest extends AbstractCrudsWebTest
9
{
10
    /**
11
     * @dataProvider getKernelClasses
12
     *
13
     * @param $kernel
14
     */
15 View Code Duplication
    public function testCountAction($kernel)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        self::createAndBootKernel($kernel);
18
        self::configureDb();
19
20
        $em     = self::getEntityManager();
21
        $entity = new MyEntity('my-test-secret');
22
        $em->persist($entity);
23
        $parent = new MyEntity('non-recursing-entity');
24
        $em->persist($parent);
25
        $entity->setParent($parent);
26
        $em->flush();
27
        $em->clear();
28
29
        $client = self::createClient();
30
        $client->request(
31
            'GET',
32
            '/api/entity/my-entity/count',
33
            [
34
                'criteria' => [],
35
            ],
36
            [],
37
            ['HTTP_CONTENT_TYPE' => 'application/json']
38
        );
39
        $response = $client->getResponse();
40
41
        self::assertTrue($response->isSuccessful());
42
        $data = json_decode($response->getContent());
43
44
        self::assertEquals(JSON_ERROR_NONE, json_last_error());
45
        self::assertEquals(2, $data);
46
    }
47
48
    /**
49
     * @dataProvider getKernelClasses
50
     *
51
     * @param $kernel
52
     */
53 View Code Duplication
    public function testCountWithRelation($kernel)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        self::createAndBootKernel($kernel);
56
        self::configureDb();
57
58
        $em     = self::getEntityManager();
59
        $entity = new MyEntity('my-test-secret');
60
        $em->persist($entity);
61
        $parent = new MyEntity('non-recursing-entity');
62
        $em->persist($parent);
63
        $entity->setParent($parent);
64
        $em->flush();
65
        $em->clear();
66
67
        $client = self::createClient();
68
        $client->request(
69
            'GET',
70
            '/api/entity/my-entity/count',
71
            [
72
                'criteria' => [
73
                    'parent' => $parent->getId(),
74
                ],
75
            ],
76
            [],
77
            ['HTTP_CONTENT_TYPE' => 'application/json']
78
        );
79
        $response = $client->getResponse();
80
81
        self::assertTrue($response->isSuccessful());
82
        $data = json_decode($response->getContent());
83
84
        self::assertEquals(JSON_ERROR_NONE, json_last_error());
85
        self::assertEquals(1, $data);
86
    }
87
}
88