Completed
Push — feature/EVO-7278-security-and-... ( ec06f5...19a53c )
by
unknown
29:18 queued 24:23
created

SerializerSelectExclusionStrategyTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 44.78 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 15 3
A testRqlSelectionOnArrays() 15 15 1
A testRqlSelectionOnNested() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * SerializerSelectExclusionStrategyTest class file
4
 */
5
6
namespace Graviton\CoreBundle\Tests\Controller;
7
8
use Graviton\TestBundle\Test\RestTestCase;
9
use Symfony\Component\HttpFoundation\Response;
10
use GravitonDyn\TestCasePrimitiveArrayBundle\DataFixtures\MongoDB\LoadTestCasePrimitiveArrayData;
11
use GravitonDyn\TestCaseNullExtrefBundle\DataFixtures\MongoDB\LoadTestCaseNullExtrefData;
12
13
/**
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class SerializerSelectExclusionStrategyTest extends RestTestCase
19
{
20
    const DATE_FORMAT = 'Y-m-d\\TH:i:sO';
21
22
    /**
23
     * load fixtures (in this case we can reuse fixtures from other tests)
24
     *
25
     * @return void
26
     */
27
    public function setUp()
28
    {
29
        if (!class_exists(LoadTestCasePrimitiveArrayData::class)) {
30
            $this->markTestSkipped('TestCasePrimitiveArray definition is not loaded');
31
        }
32
        if (!class_exists(LoadTestCaseNullExtrefData::class)) {
33
            $this->markTestSkipped('TestCaseNullExtref definition is not loaded');
34
        }
35
36
        $this->loadFixtures(
37
            [LoadTestCasePrimitiveArrayData::class, LoadTestCaseNullExtrefData::class],
38
            null,
39
            'doctrine_mongodb'
40
        );
41
    }
42
43
    /**
44
     * Test testRqlSelectionOnArrays testing the correct serialization of nested arrays
45
     *
46
     * @return void
47
     */
48 View Code Duplication
    public function testRqlSelectionOnArrays()
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...
49
    {
50
        $expectedResult = json_decode(
51
            file_get_contents(dirname(__FILE__).'/../resources/serializer-exclusion-array.json'),
52
            false
53
        );
54
55
        $client = static::createRestClient();
56
        $client->request(
57
            'GET',
58
            '/testcase/primitivearray/testdata?select(hash.strarray,arrayhash.intarray,arrayhash.hasharray)'
59
        );
60
        $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
61
        $this->assertEquals($expectedResult, $client->getResults());
62
    }
63
64
    /**
65
     * Test testRqlSelectionOnNested testing the correct serialization of deeply nested values
66
     *
67
     * @return void
68
     */
69 View Code Duplication
    public function testRqlSelectionOnNested()
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...
70
    {
71
        $expectedResult = json_decode(
72
            file_get_contents(dirname(__FILE__).'/../resources/serializer-exclusion-nested.json'),
73
            false
74
        );
75
76
        $client = static::createRestClient();
77
        $client->request(
78
            'GET',
79
            '/testcase/nullextref/testdata?select(requiredExtref,requiredExtrefDeep.deep.deep,optionalExtrefDeep)'
80
        );
81
        $this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
82
        $this->assertEquals($expectedResult, $client->getResults());
83
    }
84
}
85