We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
17 | class GraphControllerTest extends TestCase |
||
18 | { |
||
19 | private $friendsQuery = <<<'EOF' |
||
20 | query FriendsQuery { |
||
21 | user { |
||
22 | friends(first: 2) { |
||
23 | totalCount |
||
24 | edges { |
||
25 | friendshipTime |
||
26 | node { |
||
27 | name |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | EOF; |
||
34 | |||
35 | private $friendsTotalCountQuery = <<<'EOF' |
||
36 | query FriendsTotalCountQuery { |
||
37 | user { |
||
38 | friends { |
||
39 | totalCount |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | EOF; |
||
44 | |||
45 | private $expectedData = [ |
||
46 | 'user' => [ |
||
47 | 'friends' => [ |
||
48 | 'totalCount' => 4, |
||
49 | 'edges' => [ |
||
50 | [ |
||
51 | 'friendshipTime' => 'Yesterday', |
||
52 | 'node' => [ |
||
53 | 'name' => 'Nick', |
||
54 | ], |
||
55 | ], |
||
56 | [ |
||
57 | 'friendshipTime' => 'Yesterday', |
||
58 | 'node' => [ |
||
59 | 'name' => 'Lee', |
||
60 | ], |
||
61 | ], |
||
62 | ], |
||
63 | ], |
||
64 | ], |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * @param $uri |
||
69 | * @dataProvider graphQLEndpointUriProvider |
||
70 | */ |
||
71 | View Code Duplication | public function testEndpointAction($uri) |
|
80 | |||
81 | public function graphQLEndpointUriProvider() |
||
88 | |||
89 | /** |
||
90 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
91 | * @expectedExceptionMessage Must provide query parameter |
||
92 | */ |
||
93 | public function testEndpointWithEmptyQuery() |
||
99 | |||
100 | /** |
||
101 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
102 | * @expectedExceptionMessage The request content body must not be empty when using json content type request. |
||
103 | */ |
||
104 | public function testEndpointWithEmptyJsonBodyQuery() |
||
110 | |||
111 | /** |
||
112 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
113 | * @expectedExceptionMessage POST body sent invalid JSON |
||
114 | */ |
||
115 | public function testEndpointWithInvalidBodyQuery() |
||
121 | |||
122 | public function testEndpointActionWithVariables() |
||
123 | { |
||
124 | $client = static::createClient(['test_case' => 'connection']); |
||
125 | |||
126 | $query = <<<'EOF' |
||
127 | query FriendsQuery($firstFriends: Int) { |
||
128 | user { |
||
129 | friends(first: $firstFriends) { |
||
130 | totalCount |
||
131 | edges { |
||
132 | friendshipTime |
||
133 | node { |
||
134 | name |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | EOF; |
||
141 | |||
142 | $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}'])); |
||
143 | |||
144 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
149 | * @expectedExceptionMessage Variables are invalid JSON |
||
150 | */ |
||
151 | View Code Duplication | public function testEndpointActionWithInvalidVariables() |
|
163 | |||
164 | /** |
||
165 | * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
166 | * @expectedExceptionMessage Could not found "fake" schema. |
||
167 | */ |
||
168 | View Code Duplication | public function testMultipleEndpointActionWithUnknownSchemaName() |
|
180 | |||
181 | public function testEndpointActionWithOperationName() |
||
191 | |||
192 | /** |
||
193 | * @param $uri |
||
194 | * @dataProvider graphQLBatchEndpointUriProvider |
||
195 | */ |
||
196 | public function testBatchEndpointAction($uri) |
||
220 | |||
221 | public function graphQLBatchEndpointUriProvider() |
||
228 | |||
229 | /** |
||
230 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
231 | * @expectedExceptionMessage Must provide at least one valid query. |
||
232 | */ |
||
233 | public function testBatchEndpointWithEmptyQuery() |
||
239 | |||
240 | /** |
||
241 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
242 | * @expectedExceptionMessage Only request with content type "application/json" is accepted. |
||
243 | */ |
||
244 | public function testBatchEndpointWrongContentType() |
||
250 | |||
251 | /** |
||
252 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
253 | * @expectedExceptionMessage POST body sent invalid JSON |
||
254 | */ |
||
255 | public function testBatchEndpointWithInvalidJson() |
||
261 | |||
262 | /** |
||
263 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
264 | * @expectedExceptionMessage 1 is not a valid query |
||
265 | */ |
||
266 | public function testBatchEndpointWithInvalidQuery() |
||
272 | |||
273 | public function testPreflightedRequestWhenDisabled() |
||
281 | |||
282 | public function testUnAuthorizedMethod() |
||
288 | |||
289 | public function testPreflightedRequestWhenEnabled() |
||
295 | |||
296 | View Code Duplication | public function testNoCORSHeadersIfOriginHeaderNotExists() |
|
305 | |||
306 | private function assertCORSHeadersNotExists(Client $client) |
||
315 | |||
316 | private function assertCORSHeadersExists(Client $client) |
||
326 | } |
||
327 |
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.