Completed
Push — master ( 714b6a...f9d007 )
by Narcotic
06:13
created

GroupSerializationTest::gsDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 89
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 89
rs 8.5731
c 1
b 0
f 0
cc 1
eloc 56
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * test class for the "group" serialization feature
4
 */
5
6
namespace Graviton\RestBundle\Tests\Controller;
7
8
use Graviton\TestBundle\Test\RestTestCase;
9
use GravitonDyn\TestCaseGroupSerializationBundle\DataFixtures\MongoDB\LoadTestCaseGroupSerializationData;
10
11
/**
12
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
13
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
14
 * @link     http://swisscom.ch
15
 */
16
class GroupSerializationTest extends RestTestCase
17
{
18
19
    /**
20
     * load fixtures
21
     *
22
     * @return void
23
     */
24
    public function setUp()
25
    {
26
        $this->loadFixtures(
27
            [
28
                LoadTestCaseGroupSerializationData::class
29
            ],
30
            null,
31
            'doctrine_mongodb'
32
        );
33
    }
34
35
    /**
36
     * test if our group settings are visible in schema
37
     *
38
     * @return void
39
     */
40
    public function testSchemaPresence()
41
    {
42
        $client = static::createRestClient();
43
        $client->request('GET', '/schema/testcase/group-serialization/item');
44
        $results = $client->getResults();
45
46
        $this->assertEquals([], $results->properties->field1->{'x-groups'});
47
        $this->assertEquals(['hans'], $results->properties->field2->{'x-groups'});
48
        $this->assertEquals(['fred'], $results->properties->field3->{'x-groups'});
49
        $this->assertEquals(['hans', 'fred'], $results->properties->field4->{'x-groups'});
50
    }
51
52
    /**
53
     * check handling of the serializer group implementation and header
54
     *
55
     * @param array  $data        data
56
     * @param string $headerValue header value
57
     * @param string $rql         rql
58
     *
59
     * @dataProvider gsDataProvider
60
     *
61
     * @return void
62
     */
63
    public function testCorrectGroupSerialization($data, $headerValue, $rql)
64
    {
65
        $client = static::createRestClient();
66
67
        if (is_null($headerValue)) {
68
            $serverVars = [];
69
        } else {
70
            $serverVars['HTTP_X-GROUPS'] = $headerValue;
71
        }
72
73
        $url = '/testcase/group-serialization/';
74
        if (!is_null($rql)) {
75
            $url .= '?'.$rql;
76
        }
77
78
        $client->request('GET', $url, [], [], $serverVars);
79
        $results = $client->getResults();
80
81
        $this->assertCount(2, $results);
82
83
        foreach ($data as $singleResult) {
84
            $this->assertContains($singleResult, $results, '', false, false);
85
        }
86
    }
87
88
    /**
89
     * data provider for test
90
     *
91
     * @return array data
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
92
     */
93
    public function gsDataProvider()
94
    {
95
        return [
96
            'default' => [
97
                [
98
                    (object) [
99
                        'field1' => 'value1'
100
                    ],
101
                    (object) [
102
                        'field1' => 'second-value1'
103
                    ]
104
                ],
105
                null,
106
                null
107
            ],
108
            'group-hans' => [
109
                [
110
                    (object) [
111
                        'field1' => 'value1',
112
                        'field2' => 'value2',
113
                        'field4' => 'value4'
114
                    ],
115
                    (object) [
116
                        'field1' => 'second-value1',
117
                        'field2' => 'second-value2',
118
                        'field4' => 'second-value4'
119
                    ]
120
                ],
121
                'hans',
122
                null
123
            ],
124
            'group-fred' => [
125
                [
126
                    (object) [
127
                        'field1' => 'value1',
128
                        'field3' => 'value3',
129
                        'field4' => 'value4'
130
                    ],
131
                    (object) [
132
                        'field1' => 'second-value1',
133
                        'field3' => 'second-value3',
134
                        'field4' => 'second-value4'
135
                    ]
136
                ],
137
                'fred',
138
                null
139
            ],
140
            'group-hans-fred' => [
141
                [
142
                    (object) [
143
                        'field1' => 'value1',
144
                        'field2' => 'value2',
145
                        'field3' => 'value3',
146
                        'field4' => 'value4'
147
                    ],
148
                    (object) [
149
                        'field1' => 'second-value1',
150
                        'field2' => 'second-value2',
151
                        'field3' => 'second-value3',
152
                        'field4' => 'second-value4'
153
                    ]
154
                ],
155
                'hans, fred',
156
                null
157
            ],
158
            'group-hans-rql-not-allowed-field' => [
159
                [
160
                    (object) [
161
                    ],
162
                    (object) [
163
                    ]
164
                ],
165
                'hans',
166
                'select(field3)'
167
            ],
168
            'group-fred-rql-allowed-field' => [
169
                [
170
                    (object) [
171
                        'field3' => 'value3'
172
                    ],
173
                    (object) [
174
                        'field3' => 'second-value3'
175
                    ]
176
                ],
177
                'fred',
178
                'select(field3)'
179
            ]
180
        ];
181
    }
182
}
183