We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $node |
43 | 43 | ->isRequired() |
44 | 44 | ->validate() |
45 | - ->ifTrue(fn ($name) => !preg_match('/^[_a-z][_0-9a-z]*$/i', $name)) |
|
45 | + ->ifTrue(fn($name) => !preg_match('/^[_a-z][_0-9a-z]*$/i', $name)) |
|
46 | 46 | ->thenInvalid('Invalid type name "%s". (see http://spec.graphql.org/June2018/#sec-Names)') |
47 | 47 | ->end() |
48 | 48 | ; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | $node |
159 | 159 | ->beforeNormalization() |
160 | - ->ifTrue(fn ($options) => !empty($options[$old]) && empty($options[$new])) |
|
160 | + ->ifTrue(fn($options) => !empty($options[$old]) && empty($options[$new])) |
|
161 | 161 | ->then(function ($options) use ($old, $new) { |
162 | 162 | if (is_callable($options[$old])) { |
163 | 163 | if (is_array($options[$old])) { |
@@ -167,8 +167,7 @@ discard block |
||
167 | 167 | } |
168 | 168 | } elseif (is_string($options[$old])) { |
169 | 169 | $options[$new]['expression'] = ExpressionLanguage::stringHasTrigger($options[$old]) ? |
170 | - ExpressionLanguage::unprefixExpression($options[$old]) : |
|
171 | - json_encode($options[$old]); |
|
170 | + ExpressionLanguage::unprefixExpression($options[$old]) : json_encode($options[$old]); |
|
172 | 171 | } else { |
173 | 172 | $options[$new]['expression'] = json_encode($options[$old]); |
174 | 173 | } |
@@ -177,7 +176,7 @@ discard block |
||
177 | 176 | }) |
178 | 177 | ->end() |
179 | 178 | ->beforeNormalization() |
180 | - ->ifTrue(fn ($options) => is_array($options) && array_key_exists($old, $options)) |
|
179 | + ->ifTrue(fn($options) => is_array($options) && array_key_exists($old, $options)) |
|
181 | 180 | ->then(function ($options) use ($old) { |
182 | 181 | unset($options[$old]); |
183 | 182 | |
@@ -185,7 +184,7 @@ discard block |
||
185 | 184 | }) |
186 | 185 | ->end() |
187 | 186 | ->validate() |
188 | - ->ifTrue(fn (array $v) => !empty($v[$new]) && !empty($v[$old])) |
|
187 | + ->ifTrue(fn(array $v) => !empty($v[$new]) && !empty($v[$old])) |
|
189 | 188 | ->thenInvalid(sprintf( |
190 | 189 | '"%s" and "%s" should not be used together in "%%s".', |
191 | 190 | $new, |
@@ -203,17 +202,17 @@ discard block |
||
203 | 202 | $node |
204 | 203 | ->info($info) |
205 | 204 | ->validate() |
206 | - ->ifTrue(fn (array $v) => !empty($v['function']) && !empty($v['expression'])) |
|
205 | + ->ifTrue(fn(array $v) => !empty($v['function']) && !empty($v['expression'])) |
|
207 | 206 | ->thenInvalid('"function" and "expression" should not be use together.') |
208 | 207 | ->end() |
209 | 208 | ->beforeNormalization() |
210 | 209 | // Allow short syntax |
211 | - ->ifTrue(fn ($options) => is_string($options) && ExpressionLanguage::stringHasTrigger($options)) |
|
212 | - ->then(fn ($options) => ['expression' => ExpressionLanguage::unprefixExpression($options)]) |
|
210 | + ->ifTrue(fn($options) => is_string($options) && ExpressionLanguage::stringHasTrigger($options)) |
|
211 | + ->then(fn($options) => ['expression' => ExpressionLanguage::unprefixExpression($options)]) |
|
213 | 212 | ->end() |
214 | 213 | ->beforeNormalization() |
215 | - ->ifTrue(fn ($options) => is_string($options) && !ExpressionLanguage::stringHasTrigger($options)) |
|
216 | - ->then(fn ($options) => ['function' => $options]) |
|
214 | + ->ifTrue(fn($options) => is_string($options) && !ExpressionLanguage::stringHasTrigger($options)) |
|
215 | + ->then(fn($options) => ['function' => $options]) |
|
217 | 216 | ->end() |
218 | 217 | ->children() |
219 | 218 | ->scalarNode('function')->end() |
@@ -64,7 +64,7 @@ |
||
64 | 64 | $alias = $container->getAlias($id); |
65 | 65 | $id = (string) $alias; |
66 | 66 | $definition = $container->getDefinition($id); |
67 | - } catch (ServiceNotFoundException|InvalidArgumentException $e) { |
|
67 | + } catch (ServiceNotFoundException | InvalidArgumentException $e) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | } |
@@ -14,315 +14,3 @@ |
||
14 | 14 | final class GraphControllerTest extends TestCase |
15 | 15 | { |
16 | 16 | private string $friendsQuery = <<<'EOF' |
17 | - query FriendsQuery { |
|
18 | - user { |
|
19 | - friends(first: 2) { |
|
20 | - totalCount |
|
21 | - edges { |
|
22 | - friendshipTime |
|
23 | - node { |
|
24 | - name |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
28 | - } |
|
29 | - } |
|
30 | - EOF; |
|
31 | - |
|
32 | - private string $friendsTotalCountQuery = <<<'EOF' |
|
33 | - query FriendsTotalCountQuery { |
|
34 | - user { |
|
35 | - friends { |
|
36 | - totalCount |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - EOF; |
|
41 | - |
|
42 | - private array $expectedData = [ |
|
43 | - 'user' => [ |
|
44 | - 'friends' => [ |
|
45 | - 'totalCount' => 4, |
|
46 | - 'edges' => [ |
|
47 | - [ |
|
48 | - 'friendshipTime' => 'Yesterday', |
|
49 | - 'node' => [ |
|
50 | - 'name' => 'Nick', |
|
51 | - ], |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'friendshipTime' => 'Yesterday', |
|
55 | - 'node' => [ |
|
56 | - 'name' => 'Lee', |
|
57 | - ], |
|
58 | - ], |
|
59 | - ], |
|
60 | - ], |
|
61 | - ], |
|
62 | - ]; |
|
63 | - |
|
64 | - /** |
|
65 | - * @dataProvider graphQLEndpointUriProvider |
|
66 | - */ |
|
67 | - public function testEndpointAction(string $uri): void |
|
68 | - { |
|
69 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
70 | - $this->disableCatchExceptions($client); |
|
71 | - |
|
72 | - $client->request('GET', $uri, ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql;charset=utf8', 'HTTP_Origin' => 'http://example.com']); |
|
73 | - $result = $client->getResponse()->getContent(); |
|
74 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
75 | - $this->assertCORSHeadersExists($client); |
|
76 | - } |
|
77 | - |
|
78 | - public function graphQLEndpointUriProvider(): array |
|
79 | - { |
|
80 | - return [ |
|
81 | - ['/'], |
|
82 | - ['/graphql/default'], |
|
83 | - ]; |
|
84 | - } |
|
85 | - |
|
86 | - public function testEndpointWithEmptyQuery(): void |
|
87 | - { |
|
88 | - $this->expectException(BadRequestHttpException::class); |
|
89 | - $this->expectExceptionMessage('Must provide query parameter'); |
|
90 | - $client = self::createClient(); |
|
91 | - $this->disableCatchExceptions($client); |
|
92 | - $client->request('GET', '/', []); |
|
93 | - $client->getResponse()->getContent(); |
|
94 | - } |
|
95 | - |
|
96 | - public function testEndpointWithEmptyPostJsonBodyQuery(): void |
|
97 | - { |
|
98 | - $this->expectException(BadRequestHttpException::class); |
|
99 | - $this->expectExceptionMessage('The request content body must not be empty when using json content type request.'); |
|
100 | - $client = self::createClient(); |
|
101 | - $this->disableCatchExceptions($client); |
|
102 | - $client->request('POST', '/', [], [], ['CONTENT_TYPE' => 'application/json']); |
|
103 | - } |
|
104 | - |
|
105 | - public function testEndpointWithJsonContentTypeAndGetQuery(): void |
|
106 | - { |
|
107 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
108 | - $this->disableCatchExceptions($client); |
|
109 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/json']); |
|
110 | - $result = $client->getResponse()->getContent(); |
|
111 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
112 | - } |
|
113 | - |
|
114 | - public function testEndpointWithInvalidBodyQuery(): void |
|
115 | - { |
|
116 | - $this->expectException(BadRequestHttpException::class); |
|
117 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
118 | - $client = self::createClient(); |
|
119 | - $this->disableCatchExceptions($client); |
|
120 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
121 | - $client->getResponse()->getContent(); |
|
122 | - } |
|
123 | - |
|
124 | - public function testEndpointActionWithVariables(): void |
|
125 | - { |
|
126 | - $client = self::createClient(['test_case' => 'connection']); |
|
127 | - $this->disableCatchExceptions($client); |
|
128 | - |
|
129 | - $query = <<<'EOF' |
|
130 | - query FriendsQuery($firstFriends: Int) { |
|
131 | - user { |
|
132 | - friends(first: $firstFriends) { |
|
133 | - totalCount |
|
134 | - edges { |
|
135 | - friendshipTime |
|
136 | - node { |
|
137 | - name |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - EOF; |
|
144 | - |
|
145 | - $content = json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']) ?: null; |
|
146 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
147 | - $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
148 | - } |
|
149 | - |
|
150 | - public function testEndpointActionWithInvalidVariables(): void |
|
151 | - { |
|
152 | - $this->expectException(BadRequestHttpException::class); |
|
153 | - $this->expectExceptionMessage('Variables are invalid JSON'); |
|
154 | - $client = self::createClient(['test_case' => 'connection']); |
|
155 | - $this->disableCatchExceptions($client); |
|
156 | - |
|
157 | - $query = <<<'EOF' |
|
158 | - query { |
|
159 | - user |
|
160 | - } |
|
161 | - EOF; |
|
162 | - |
|
163 | - $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']); |
|
164 | - } |
|
165 | - |
|
166 | - public function testMultipleEndpointActionWithUnknownSchemaName(): void |
|
167 | - { |
|
168 | - $this->expectException(NotFoundHttpException::class); |
|
169 | - $this->expectExceptionMessage('Could not find "fake" schema.'); |
|
170 | - $client = self::createClient(['test_case' => 'connection']); |
|
171 | - $this->disableCatchExceptions($client); |
|
172 | - |
|
173 | - $query = <<<'EOF' |
|
174 | - query { |
|
175 | - user |
|
176 | - } |
|
177 | - EOF; |
|
178 | - |
|
179 | - $client->request('GET', '/graphql/fake', ['query' => $query]); |
|
180 | - } |
|
181 | - |
|
182 | - public function testEndpointActionWithOperationName(): void |
|
183 | - { |
|
184 | - $client = self::createClient(['test_case' => 'connection']); |
|
185 | - $this->disableCatchExceptions($client); |
|
186 | - |
|
187 | - $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery; |
|
188 | - |
|
189 | - $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']); |
|
190 | - $result = $client->getResponse()->getContent(); |
|
191 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @dataProvider graphQLBatchEndpointUriProvider |
|
196 | - */ |
|
197 | - public function testBatchEndpointAction(string $uri): void |
|
198 | - { |
|
199 | - $client = self::createClient(['test_case' => 'connection']); |
|
200 | - $this->disableCatchExceptions($client); |
|
201 | - |
|
202 | - $data = [ |
|
203 | - [ |
|
204 | - 'id' => 'friends', |
|
205 | - 'query' => $this->friendsQuery, |
|
206 | - ], |
|
207 | - [ |
|
208 | - 'id' => 'friendsTotalCount', |
|
209 | - 'query' => $this->friendsTotalCountQuery, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - |
|
213 | - $content = json_encode($data) ?: null; |
|
214 | - $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
215 | - $result = $client->getResponse()->getContent(); |
|
216 | - |
|
217 | - $expected = [ |
|
218 | - ['id' => 'friends', 'payload' => ['data' => $this->expectedData]], |
|
219 | - ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]], |
|
220 | - ]; |
|
221 | - $this->assertSame($expected, json_decode($result, true), $result); |
|
222 | - } |
|
223 | - |
|
224 | - public function graphQLBatchEndpointUriProvider(): array |
|
225 | - { |
|
226 | - return [ |
|
227 | - ['/batch'], |
|
228 | - ['/graphql/default/batch'], |
|
229 | - ]; |
|
230 | - } |
|
231 | - |
|
232 | - public function testBatchEndpointWithEmptyQuery(): void |
|
233 | - { |
|
234 | - $this->expectException(BadRequestHttpException::class); |
|
235 | - $this->expectExceptionMessage('Must provide at least one valid query.'); |
|
236 | - $client = self::createClient(); |
|
237 | - $this->disableCatchExceptions($client); |
|
238 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
|
239 | - $client->getResponse()->getContent(); |
|
240 | - } |
|
241 | - |
|
242 | - public function testBatchEndpointWrongContentType(): void |
|
243 | - { |
|
244 | - $this->expectException(BadRequestHttpException::class); |
|
245 | - $this->expectExceptionMessage('Batching parser only accepts "application/json" or "multipart/form-data" content-type but got "".'); |
|
246 | - $client = self::createClient(); |
|
247 | - $this->disableCatchExceptions($client); |
|
248 | - $client->request('GET', '/batch'); |
|
249 | - $client->getResponse()->getContent(); |
|
250 | - } |
|
251 | - |
|
252 | - public function testBatchEndpointWithInvalidJson(): void |
|
253 | - { |
|
254 | - $this->expectException(BadRequestHttpException::class); |
|
255 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
256 | - $client = self::createClient(); |
|
257 | - $this->disableCatchExceptions($client); |
|
258 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
259 | - $client->getResponse()->getContent(); |
|
260 | - } |
|
261 | - |
|
262 | - public function testBatchEndpointWithInvalidQuery(): void |
|
263 | - { |
|
264 | - $this->expectException(BadRequestHttpException::class); |
|
265 | - $this->expectExceptionMessage('1 is not a valid query'); |
|
266 | - $client = self::createClient(); |
|
267 | - $this->disableCatchExceptions($client); |
|
268 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}'); |
|
269 | - $client->getResponse()->getContent(); |
|
270 | - } |
|
271 | - |
|
272 | - public function testPreflightedRequestWhenDisabled(): void |
|
273 | - { |
|
274 | - $client = self::createClient(['test_case' => 'connection']); |
|
275 | - $this->disableCatchExceptions($client); |
|
276 | - $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
277 | - $response = $client->getResponse(); |
|
278 | - $this->assertSame(200, $response->getStatusCode()); |
|
279 | - $this->assertCORSHeadersNotExists($client); |
|
280 | - } |
|
281 | - |
|
282 | - public function testUnAuthorizedMethod(): void |
|
283 | - { |
|
284 | - $client = self::createClient(['test_case' => 'connection']); |
|
285 | - $this->disableCatchExceptions($client); |
|
286 | - $client->request('PUT', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
287 | - $this->assertSame(405, $client->getResponse()->getStatusCode()); |
|
288 | - } |
|
289 | - |
|
290 | - public function testPreflightedRequestWhenEnabled(): void |
|
291 | - { |
|
292 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
293 | - $this->disableCatchExceptions($client); |
|
294 | - $client->request('OPTIONS', '/batch', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
295 | - $this->assertCORSHeadersExists($client); |
|
296 | - } |
|
297 | - |
|
298 | - public function testNoCORSHeadersIfOriginHeaderNotExists(): void |
|
299 | - { |
|
300 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
301 | - $this->disableCatchExceptions($client); |
|
302 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']); |
|
303 | - $result = $client->getResponse()->getContent(); |
|
304 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
305 | - $this->assertCORSHeadersNotExists($client); |
|
306 | - } |
|
307 | - |
|
308 | - private function assertCORSHeadersNotExists(KernelBrowser $client): void |
|
309 | - { |
|
310 | - $headers = $client->getResponse()->headers->all(); |
|
311 | - $this->assertArrayNotHasKey('access-control-allow-origin', $headers); |
|
312 | - $this->assertArrayNotHasKey('access-control-allow-methods', $headers); |
|
313 | - $this->assertArrayNotHasKey('access-control-allow-credentials', $headers); |
|
314 | - $this->assertArrayNotHasKey('access-control-allow-headers', $headers); |
|
315 | - $this->assertArrayNotHasKey('access-control-max-age', $headers); |
|
316 | - } |
|
317 | - |
|
318 | - private function assertCORSHeadersExists(KernelBrowser $client): void |
|
319 | - { |
|
320 | - $response = $client->getResponse(); |
|
321 | - $this->assertSame(200, $response->getStatusCode()); |
|
322 | - $this->assertSame('http://example.com', $response->headers->get('Access-Control-Allow-Origin')); |
|
323 | - $this->assertSame('OPTIONS, GET, POST', $response->headers->get('Access-Control-Allow-Methods')); |
|
324 | - $this->assertSame('true', $response->headers->get('Access-Control-Allow-Credentials')); |
|
325 | - $this->assertSame('Content-Type, Authorization', $response->headers->get('Access-Control-Allow-Headers')); |
|
326 | - $this->assertSame('3600', $response->headers->get('Access-Control-Max-Age')); |
|
327 | - } |
|
328 | -} |
@@ -14,315 +14,3 @@ |
||
14 | 14 | final class GraphControllerTest extends TestCase |
15 | 15 | { |
16 | 16 | private string $friendsQuery = <<<'EOF' |
17 | - query FriendsQuery { |
|
18 | - user { |
|
19 | - friends(first: 2) { |
|
20 | - totalCount |
|
21 | - edges { |
|
22 | - friendshipTime |
|
23 | - node { |
|
24 | - name |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
28 | - } |
|
29 | - } |
|
30 | - EOF; |
|
31 | - |
|
32 | - private string $friendsTotalCountQuery = <<<'EOF' |
|
33 | - query FriendsTotalCountQuery { |
|
34 | - user { |
|
35 | - friends { |
|
36 | - totalCount |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - EOF; |
|
41 | - |
|
42 | - private array $expectedData = [ |
|
43 | - 'user' => [ |
|
44 | - 'friends' => [ |
|
45 | - 'totalCount' => 4, |
|
46 | - 'edges' => [ |
|
47 | - [ |
|
48 | - 'friendshipTime' => 'Yesterday', |
|
49 | - 'node' => [ |
|
50 | - 'name' => 'Nick', |
|
51 | - ], |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'friendshipTime' => 'Yesterday', |
|
55 | - 'node' => [ |
|
56 | - 'name' => 'Lee', |
|
57 | - ], |
|
58 | - ], |
|
59 | - ], |
|
60 | - ], |
|
61 | - ], |
|
62 | - ]; |
|
63 | - |
|
64 | - /** |
|
65 | - * @dataProvider graphQLEndpointUriProvider |
|
66 | - */ |
|
67 | - public function testEndpointAction(string $uri): void |
|
68 | - { |
|
69 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
70 | - $this->disableCatchExceptions($client); |
|
71 | - |
|
72 | - $client->request('GET', $uri, ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql;charset=utf8', 'HTTP_Origin' => 'http://example.com']); |
|
73 | - $result = $client->getResponse()->getContent(); |
|
74 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
75 | - $this->assertCORSHeadersExists($client); |
|
76 | - } |
|
77 | - |
|
78 | - public function graphQLEndpointUriProvider(): array |
|
79 | - { |
|
80 | - return [ |
|
81 | - ['/'], |
|
82 | - ['/graphql/default'], |
|
83 | - ]; |
|
84 | - } |
|
85 | - |
|
86 | - public function testEndpointWithEmptyQuery(): void |
|
87 | - { |
|
88 | - $this->expectException(BadRequestHttpException::class); |
|
89 | - $this->expectExceptionMessage('Must provide query parameter'); |
|
90 | - $client = self::createClient(); |
|
91 | - $this->disableCatchExceptions($client); |
|
92 | - $client->request('GET', '/', []); |
|
93 | - $client->getResponse()->getContent(); |
|
94 | - } |
|
95 | - |
|
96 | - public function testEndpointWithEmptyPostJsonBodyQuery(): void |
|
97 | - { |
|
98 | - $this->expectException(BadRequestHttpException::class); |
|
99 | - $this->expectExceptionMessage('The request content body must not be empty when using json content type request.'); |
|
100 | - $client = self::createClient(); |
|
101 | - $this->disableCatchExceptions($client); |
|
102 | - $client->request('POST', '/', [], [], ['CONTENT_TYPE' => 'application/json']); |
|
103 | - } |
|
104 | - |
|
105 | - public function testEndpointWithJsonContentTypeAndGetQuery(): void |
|
106 | - { |
|
107 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
108 | - $this->disableCatchExceptions($client); |
|
109 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/json']); |
|
110 | - $result = $client->getResponse()->getContent(); |
|
111 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
112 | - } |
|
113 | - |
|
114 | - public function testEndpointWithInvalidBodyQuery(): void |
|
115 | - { |
|
116 | - $this->expectException(BadRequestHttpException::class); |
|
117 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
118 | - $client = self::createClient(); |
|
119 | - $this->disableCatchExceptions($client); |
|
120 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
121 | - $client->getResponse()->getContent(); |
|
122 | - } |
|
123 | - |
|
124 | - public function testEndpointActionWithVariables(): void |
|
125 | - { |
|
126 | - $client = self::createClient(['test_case' => 'connection']); |
|
127 | - $this->disableCatchExceptions($client); |
|
128 | - |
|
129 | - $query = <<<'EOF' |
|
130 | - query FriendsQuery($firstFriends: Int) { |
|
131 | - user { |
|
132 | - friends(first: $firstFriends) { |
|
133 | - totalCount |
|
134 | - edges { |
|
135 | - friendshipTime |
|
136 | - node { |
|
137 | - name |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - EOF; |
|
144 | - |
|
145 | - $content = json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']) ?: null; |
|
146 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
147 | - $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
148 | - } |
|
149 | - |
|
150 | - public function testEndpointActionWithInvalidVariables(): void |
|
151 | - { |
|
152 | - $this->expectException(BadRequestHttpException::class); |
|
153 | - $this->expectExceptionMessage('Variables are invalid JSON'); |
|
154 | - $client = self::createClient(['test_case' => 'connection']); |
|
155 | - $this->disableCatchExceptions($client); |
|
156 | - |
|
157 | - $query = <<<'EOF' |
|
158 | - query { |
|
159 | - user |
|
160 | - } |
|
161 | - EOF; |
|
162 | - |
|
163 | - $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']); |
|
164 | - } |
|
165 | - |
|
166 | - public function testMultipleEndpointActionWithUnknownSchemaName(): void |
|
167 | - { |
|
168 | - $this->expectException(NotFoundHttpException::class); |
|
169 | - $this->expectExceptionMessage('Could not find "fake" schema.'); |
|
170 | - $client = self::createClient(['test_case' => 'connection']); |
|
171 | - $this->disableCatchExceptions($client); |
|
172 | - |
|
173 | - $query = <<<'EOF' |
|
174 | - query { |
|
175 | - user |
|
176 | - } |
|
177 | - EOF; |
|
178 | - |
|
179 | - $client->request('GET', '/graphql/fake', ['query' => $query]); |
|
180 | - } |
|
181 | - |
|
182 | - public function testEndpointActionWithOperationName(): void |
|
183 | - { |
|
184 | - $client = self::createClient(['test_case' => 'connection']); |
|
185 | - $this->disableCatchExceptions($client); |
|
186 | - |
|
187 | - $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery; |
|
188 | - |
|
189 | - $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']); |
|
190 | - $result = $client->getResponse()->getContent(); |
|
191 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @dataProvider graphQLBatchEndpointUriProvider |
|
196 | - */ |
|
197 | - public function testBatchEndpointAction(string $uri): void |
|
198 | - { |
|
199 | - $client = self::createClient(['test_case' => 'connection']); |
|
200 | - $this->disableCatchExceptions($client); |
|
201 | - |
|
202 | - $data = [ |
|
203 | - [ |
|
204 | - 'id' => 'friends', |
|
205 | - 'query' => $this->friendsQuery, |
|
206 | - ], |
|
207 | - [ |
|
208 | - 'id' => 'friendsTotalCount', |
|
209 | - 'query' => $this->friendsTotalCountQuery, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - |
|
213 | - $content = json_encode($data) ?: null; |
|
214 | - $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
215 | - $result = $client->getResponse()->getContent(); |
|
216 | - |
|
217 | - $expected = [ |
|
218 | - ['id' => 'friends', 'payload' => ['data' => $this->expectedData]], |
|
219 | - ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]], |
|
220 | - ]; |
|
221 | - $this->assertSame($expected, json_decode($result, true), $result); |
|
222 | - } |
|
223 | - |
|
224 | - public function graphQLBatchEndpointUriProvider(): array |
|
225 | - { |
|
226 | - return [ |
|
227 | - ['/batch'], |
|
228 | - ['/graphql/default/batch'], |
|
229 | - ]; |
|
230 | - } |
|
231 | - |
|
232 | - public function testBatchEndpointWithEmptyQuery(): void |
|
233 | - { |
|
234 | - $this->expectException(BadRequestHttpException::class); |
|
235 | - $this->expectExceptionMessage('Must provide at least one valid query.'); |
|
236 | - $client = self::createClient(); |
|
237 | - $this->disableCatchExceptions($client); |
|
238 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
|
239 | - $client->getResponse()->getContent(); |
|
240 | - } |
|
241 | - |
|
242 | - public function testBatchEndpointWrongContentType(): void |
|
243 | - { |
|
244 | - $this->expectException(BadRequestHttpException::class); |
|
245 | - $this->expectExceptionMessage('Batching parser only accepts "application/json" or "multipart/form-data" content-type but got "".'); |
|
246 | - $client = self::createClient(); |
|
247 | - $this->disableCatchExceptions($client); |
|
248 | - $client->request('GET', '/batch'); |
|
249 | - $client->getResponse()->getContent(); |
|
250 | - } |
|
251 | - |
|
252 | - public function testBatchEndpointWithInvalidJson(): void |
|
253 | - { |
|
254 | - $this->expectException(BadRequestHttpException::class); |
|
255 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
256 | - $client = self::createClient(); |
|
257 | - $this->disableCatchExceptions($client); |
|
258 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
259 | - $client->getResponse()->getContent(); |
|
260 | - } |
|
261 | - |
|
262 | - public function testBatchEndpointWithInvalidQuery(): void |
|
263 | - { |
|
264 | - $this->expectException(BadRequestHttpException::class); |
|
265 | - $this->expectExceptionMessage('1 is not a valid query'); |
|
266 | - $client = self::createClient(); |
|
267 | - $this->disableCatchExceptions($client); |
|
268 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}'); |
|
269 | - $client->getResponse()->getContent(); |
|
270 | - } |
|
271 | - |
|
272 | - public function testPreflightedRequestWhenDisabled(): void |
|
273 | - { |
|
274 | - $client = self::createClient(['test_case' => 'connection']); |
|
275 | - $this->disableCatchExceptions($client); |
|
276 | - $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
277 | - $response = $client->getResponse(); |
|
278 | - $this->assertSame(200, $response->getStatusCode()); |
|
279 | - $this->assertCORSHeadersNotExists($client); |
|
280 | - } |
|
281 | - |
|
282 | - public function testUnAuthorizedMethod(): void |
|
283 | - { |
|
284 | - $client = self::createClient(['test_case' => 'connection']); |
|
285 | - $this->disableCatchExceptions($client); |
|
286 | - $client->request('PUT', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
287 | - $this->assertSame(405, $client->getResponse()->getStatusCode()); |
|
288 | - } |
|
289 | - |
|
290 | - public function testPreflightedRequestWhenEnabled(): void |
|
291 | - { |
|
292 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
293 | - $this->disableCatchExceptions($client); |
|
294 | - $client->request('OPTIONS', '/batch', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
295 | - $this->assertCORSHeadersExists($client); |
|
296 | - } |
|
297 | - |
|
298 | - public function testNoCORSHeadersIfOriginHeaderNotExists(): void |
|
299 | - { |
|
300 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
301 | - $this->disableCatchExceptions($client); |
|
302 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']); |
|
303 | - $result = $client->getResponse()->getContent(); |
|
304 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
305 | - $this->assertCORSHeadersNotExists($client); |
|
306 | - } |
|
307 | - |
|
308 | - private function assertCORSHeadersNotExists(KernelBrowser $client): void |
|
309 | - { |
|
310 | - $headers = $client->getResponse()->headers->all(); |
|
311 | - $this->assertArrayNotHasKey('access-control-allow-origin', $headers); |
|
312 | - $this->assertArrayNotHasKey('access-control-allow-methods', $headers); |
|
313 | - $this->assertArrayNotHasKey('access-control-allow-credentials', $headers); |
|
314 | - $this->assertArrayNotHasKey('access-control-allow-headers', $headers); |
|
315 | - $this->assertArrayNotHasKey('access-control-max-age', $headers); |
|
316 | - } |
|
317 | - |
|
318 | - private function assertCORSHeadersExists(KernelBrowser $client): void |
|
319 | - { |
|
320 | - $response = $client->getResponse(); |
|
321 | - $this->assertSame(200, $response->getStatusCode()); |
|
322 | - $this->assertSame('http://example.com', $response->headers->get('Access-Control-Allow-Origin')); |
|
323 | - $this->assertSame('OPTIONS, GET, POST', $response->headers->get('Access-Control-Allow-Methods')); |
|
324 | - $this->assertSame('true', $response->headers->get('Access-Control-Allow-Credentials')); |
|
325 | - $this->assertSame('Content-Type, Authorization', $response->headers->get('Access-Control-Allow-Headers')); |
|
326 | - $this->assertSame('3600', $response->headers->get('Access-Control-Max-Age')); |
|
327 | - } |
|
328 | -} |
@@ -14,315 +14,3 @@ |
||
14 | 14 | final class GraphControllerTest extends TestCase |
15 | 15 | { |
16 | 16 | private string $friendsQuery = <<<'EOF' |
17 | - query FriendsQuery { |
|
18 | - user { |
|
19 | - friends(first: 2) { |
|
20 | - totalCount |
|
21 | - edges { |
|
22 | - friendshipTime |
|
23 | - node { |
|
24 | - name |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
28 | - } |
|
29 | - } |
|
30 | - EOF; |
|
31 | - |
|
32 | - private string $friendsTotalCountQuery = <<<'EOF' |
|
33 | - query FriendsTotalCountQuery { |
|
34 | - user { |
|
35 | - friends { |
|
36 | - totalCount |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - EOF; |
|
41 | - |
|
42 | - private array $expectedData = [ |
|
43 | - 'user' => [ |
|
44 | - 'friends' => [ |
|
45 | - 'totalCount' => 4, |
|
46 | - 'edges' => [ |
|
47 | - [ |
|
48 | - 'friendshipTime' => 'Yesterday', |
|
49 | - 'node' => [ |
|
50 | - 'name' => 'Nick', |
|
51 | - ], |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'friendshipTime' => 'Yesterday', |
|
55 | - 'node' => [ |
|
56 | - 'name' => 'Lee', |
|
57 | - ], |
|
58 | - ], |
|
59 | - ], |
|
60 | - ], |
|
61 | - ], |
|
62 | - ]; |
|
63 | - |
|
64 | - /** |
|
65 | - * @dataProvider graphQLEndpointUriProvider |
|
66 | - */ |
|
67 | - public function testEndpointAction(string $uri): void |
|
68 | - { |
|
69 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
70 | - $this->disableCatchExceptions($client); |
|
71 | - |
|
72 | - $client->request('GET', $uri, ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql;charset=utf8', 'HTTP_Origin' => 'http://example.com']); |
|
73 | - $result = $client->getResponse()->getContent(); |
|
74 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
75 | - $this->assertCORSHeadersExists($client); |
|
76 | - } |
|
77 | - |
|
78 | - public function graphQLEndpointUriProvider(): array |
|
79 | - { |
|
80 | - return [ |
|
81 | - ['/'], |
|
82 | - ['/graphql/default'], |
|
83 | - ]; |
|
84 | - } |
|
85 | - |
|
86 | - public function testEndpointWithEmptyQuery(): void |
|
87 | - { |
|
88 | - $this->expectException(BadRequestHttpException::class); |
|
89 | - $this->expectExceptionMessage('Must provide query parameter'); |
|
90 | - $client = self::createClient(); |
|
91 | - $this->disableCatchExceptions($client); |
|
92 | - $client->request('GET', '/', []); |
|
93 | - $client->getResponse()->getContent(); |
|
94 | - } |
|
95 | - |
|
96 | - public function testEndpointWithEmptyPostJsonBodyQuery(): void |
|
97 | - { |
|
98 | - $this->expectException(BadRequestHttpException::class); |
|
99 | - $this->expectExceptionMessage('The request content body must not be empty when using json content type request.'); |
|
100 | - $client = self::createClient(); |
|
101 | - $this->disableCatchExceptions($client); |
|
102 | - $client->request('POST', '/', [], [], ['CONTENT_TYPE' => 'application/json']); |
|
103 | - } |
|
104 | - |
|
105 | - public function testEndpointWithJsonContentTypeAndGetQuery(): void |
|
106 | - { |
|
107 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
108 | - $this->disableCatchExceptions($client); |
|
109 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/json']); |
|
110 | - $result = $client->getResponse()->getContent(); |
|
111 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
112 | - } |
|
113 | - |
|
114 | - public function testEndpointWithInvalidBodyQuery(): void |
|
115 | - { |
|
116 | - $this->expectException(BadRequestHttpException::class); |
|
117 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
118 | - $client = self::createClient(); |
|
119 | - $this->disableCatchExceptions($client); |
|
120 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
121 | - $client->getResponse()->getContent(); |
|
122 | - } |
|
123 | - |
|
124 | - public function testEndpointActionWithVariables(): void |
|
125 | - { |
|
126 | - $client = self::createClient(['test_case' => 'connection']); |
|
127 | - $this->disableCatchExceptions($client); |
|
128 | - |
|
129 | - $query = <<<'EOF' |
|
130 | - query FriendsQuery($firstFriends: Int) { |
|
131 | - user { |
|
132 | - friends(first: $firstFriends) { |
|
133 | - totalCount |
|
134 | - edges { |
|
135 | - friendshipTime |
|
136 | - node { |
|
137 | - name |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - EOF; |
|
144 | - |
|
145 | - $content = json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']) ?: null; |
|
146 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
147 | - $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
148 | - } |
|
149 | - |
|
150 | - public function testEndpointActionWithInvalidVariables(): void |
|
151 | - { |
|
152 | - $this->expectException(BadRequestHttpException::class); |
|
153 | - $this->expectExceptionMessage('Variables are invalid JSON'); |
|
154 | - $client = self::createClient(['test_case' => 'connection']); |
|
155 | - $this->disableCatchExceptions($client); |
|
156 | - |
|
157 | - $query = <<<'EOF' |
|
158 | - query { |
|
159 | - user |
|
160 | - } |
|
161 | - EOF; |
|
162 | - |
|
163 | - $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']); |
|
164 | - } |
|
165 | - |
|
166 | - public function testMultipleEndpointActionWithUnknownSchemaName(): void |
|
167 | - { |
|
168 | - $this->expectException(NotFoundHttpException::class); |
|
169 | - $this->expectExceptionMessage('Could not find "fake" schema.'); |
|
170 | - $client = self::createClient(['test_case' => 'connection']); |
|
171 | - $this->disableCatchExceptions($client); |
|
172 | - |
|
173 | - $query = <<<'EOF' |
|
174 | - query { |
|
175 | - user |
|
176 | - } |
|
177 | - EOF; |
|
178 | - |
|
179 | - $client->request('GET', '/graphql/fake', ['query' => $query]); |
|
180 | - } |
|
181 | - |
|
182 | - public function testEndpointActionWithOperationName(): void |
|
183 | - { |
|
184 | - $client = self::createClient(['test_case' => 'connection']); |
|
185 | - $this->disableCatchExceptions($client); |
|
186 | - |
|
187 | - $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery; |
|
188 | - |
|
189 | - $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']); |
|
190 | - $result = $client->getResponse()->getContent(); |
|
191 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @dataProvider graphQLBatchEndpointUriProvider |
|
196 | - */ |
|
197 | - public function testBatchEndpointAction(string $uri): void |
|
198 | - { |
|
199 | - $client = self::createClient(['test_case' => 'connection']); |
|
200 | - $this->disableCatchExceptions($client); |
|
201 | - |
|
202 | - $data = [ |
|
203 | - [ |
|
204 | - 'id' => 'friends', |
|
205 | - 'query' => $this->friendsQuery, |
|
206 | - ], |
|
207 | - [ |
|
208 | - 'id' => 'friendsTotalCount', |
|
209 | - 'query' => $this->friendsTotalCountQuery, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - |
|
213 | - $content = json_encode($data) ?: null; |
|
214 | - $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
215 | - $result = $client->getResponse()->getContent(); |
|
216 | - |
|
217 | - $expected = [ |
|
218 | - ['id' => 'friends', 'payload' => ['data' => $this->expectedData]], |
|
219 | - ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]], |
|
220 | - ]; |
|
221 | - $this->assertSame($expected, json_decode($result, true), $result); |
|
222 | - } |
|
223 | - |
|
224 | - public function graphQLBatchEndpointUriProvider(): array |
|
225 | - { |
|
226 | - return [ |
|
227 | - ['/batch'], |
|
228 | - ['/graphql/default/batch'], |
|
229 | - ]; |
|
230 | - } |
|
231 | - |
|
232 | - public function testBatchEndpointWithEmptyQuery(): void |
|
233 | - { |
|
234 | - $this->expectException(BadRequestHttpException::class); |
|
235 | - $this->expectExceptionMessage('Must provide at least one valid query.'); |
|
236 | - $client = self::createClient(); |
|
237 | - $this->disableCatchExceptions($client); |
|
238 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
|
239 | - $client->getResponse()->getContent(); |
|
240 | - } |
|
241 | - |
|
242 | - public function testBatchEndpointWrongContentType(): void |
|
243 | - { |
|
244 | - $this->expectException(BadRequestHttpException::class); |
|
245 | - $this->expectExceptionMessage('Batching parser only accepts "application/json" or "multipart/form-data" content-type but got "".'); |
|
246 | - $client = self::createClient(); |
|
247 | - $this->disableCatchExceptions($client); |
|
248 | - $client->request('GET', '/batch'); |
|
249 | - $client->getResponse()->getContent(); |
|
250 | - } |
|
251 | - |
|
252 | - public function testBatchEndpointWithInvalidJson(): void |
|
253 | - { |
|
254 | - $this->expectException(BadRequestHttpException::class); |
|
255 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
256 | - $client = self::createClient(); |
|
257 | - $this->disableCatchExceptions($client); |
|
258 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
259 | - $client->getResponse()->getContent(); |
|
260 | - } |
|
261 | - |
|
262 | - public function testBatchEndpointWithInvalidQuery(): void |
|
263 | - { |
|
264 | - $this->expectException(BadRequestHttpException::class); |
|
265 | - $this->expectExceptionMessage('1 is not a valid query'); |
|
266 | - $client = self::createClient(); |
|
267 | - $this->disableCatchExceptions($client); |
|
268 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}'); |
|
269 | - $client->getResponse()->getContent(); |
|
270 | - } |
|
271 | - |
|
272 | - public function testPreflightedRequestWhenDisabled(): void |
|
273 | - { |
|
274 | - $client = self::createClient(['test_case' => 'connection']); |
|
275 | - $this->disableCatchExceptions($client); |
|
276 | - $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
277 | - $response = $client->getResponse(); |
|
278 | - $this->assertSame(200, $response->getStatusCode()); |
|
279 | - $this->assertCORSHeadersNotExists($client); |
|
280 | - } |
|
281 | - |
|
282 | - public function testUnAuthorizedMethod(): void |
|
283 | - { |
|
284 | - $client = self::createClient(['test_case' => 'connection']); |
|
285 | - $this->disableCatchExceptions($client); |
|
286 | - $client->request('PUT', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
287 | - $this->assertSame(405, $client->getResponse()->getStatusCode()); |
|
288 | - } |
|
289 | - |
|
290 | - public function testPreflightedRequestWhenEnabled(): void |
|
291 | - { |
|
292 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
293 | - $this->disableCatchExceptions($client); |
|
294 | - $client->request('OPTIONS', '/batch', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
295 | - $this->assertCORSHeadersExists($client); |
|
296 | - } |
|
297 | - |
|
298 | - public function testNoCORSHeadersIfOriginHeaderNotExists(): void |
|
299 | - { |
|
300 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
301 | - $this->disableCatchExceptions($client); |
|
302 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']); |
|
303 | - $result = $client->getResponse()->getContent(); |
|
304 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
305 | - $this->assertCORSHeadersNotExists($client); |
|
306 | - } |
|
307 | - |
|
308 | - private function assertCORSHeadersNotExists(KernelBrowser $client): void |
|
309 | - { |
|
310 | - $headers = $client->getResponse()->headers->all(); |
|
311 | - $this->assertArrayNotHasKey('access-control-allow-origin', $headers); |
|
312 | - $this->assertArrayNotHasKey('access-control-allow-methods', $headers); |
|
313 | - $this->assertArrayNotHasKey('access-control-allow-credentials', $headers); |
|
314 | - $this->assertArrayNotHasKey('access-control-allow-headers', $headers); |
|
315 | - $this->assertArrayNotHasKey('access-control-max-age', $headers); |
|
316 | - } |
|
317 | - |
|
318 | - private function assertCORSHeadersExists(KernelBrowser $client): void |
|
319 | - { |
|
320 | - $response = $client->getResponse(); |
|
321 | - $this->assertSame(200, $response->getStatusCode()); |
|
322 | - $this->assertSame('http://example.com', $response->headers->get('Access-Control-Allow-Origin')); |
|
323 | - $this->assertSame('OPTIONS, GET, POST', $response->headers->get('Access-Control-Allow-Methods')); |
|
324 | - $this->assertSame('true', $response->headers->get('Access-Control-Allow-Credentials')); |
|
325 | - $this->assertSame('Content-Type, Authorization', $response->headers->get('Access-Control-Allow-Headers')); |
|
326 | - $this->assertSame('3600', $response->headers->get('Access-Control-Max-Age')); |
|
327 | - } |
|
328 | -} |
@@ -14,315 +14,3 @@ |
||
14 | 14 | final class GraphControllerTest extends TestCase |
15 | 15 | { |
16 | 16 | private string $friendsQuery = <<<'EOF' |
17 | - query FriendsQuery { |
|
18 | - user { |
|
19 | - friends(first: 2) { |
|
20 | - totalCount |
|
21 | - edges { |
|
22 | - friendshipTime |
|
23 | - node { |
|
24 | - name |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
28 | - } |
|
29 | - } |
|
30 | - EOF; |
|
31 | - |
|
32 | - private string $friendsTotalCountQuery = <<<'EOF' |
|
33 | - query FriendsTotalCountQuery { |
|
34 | - user { |
|
35 | - friends { |
|
36 | - totalCount |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - EOF; |
|
41 | - |
|
42 | - private array $expectedData = [ |
|
43 | - 'user' => [ |
|
44 | - 'friends' => [ |
|
45 | - 'totalCount' => 4, |
|
46 | - 'edges' => [ |
|
47 | - [ |
|
48 | - 'friendshipTime' => 'Yesterday', |
|
49 | - 'node' => [ |
|
50 | - 'name' => 'Nick', |
|
51 | - ], |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'friendshipTime' => 'Yesterday', |
|
55 | - 'node' => [ |
|
56 | - 'name' => 'Lee', |
|
57 | - ], |
|
58 | - ], |
|
59 | - ], |
|
60 | - ], |
|
61 | - ], |
|
62 | - ]; |
|
63 | - |
|
64 | - /** |
|
65 | - * @dataProvider graphQLEndpointUriProvider |
|
66 | - */ |
|
67 | - public function testEndpointAction(string $uri): void |
|
68 | - { |
|
69 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
70 | - $this->disableCatchExceptions($client); |
|
71 | - |
|
72 | - $client->request('GET', $uri, ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql;charset=utf8', 'HTTP_Origin' => 'http://example.com']); |
|
73 | - $result = $client->getResponse()->getContent(); |
|
74 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
75 | - $this->assertCORSHeadersExists($client); |
|
76 | - } |
|
77 | - |
|
78 | - public function graphQLEndpointUriProvider(): array |
|
79 | - { |
|
80 | - return [ |
|
81 | - ['/'], |
|
82 | - ['/graphql/default'], |
|
83 | - ]; |
|
84 | - } |
|
85 | - |
|
86 | - public function testEndpointWithEmptyQuery(): void |
|
87 | - { |
|
88 | - $this->expectException(BadRequestHttpException::class); |
|
89 | - $this->expectExceptionMessage('Must provide query parameter'); |
|
90 | - $client = self::createClient(); |
|
91 | - $this->disableCatchExceptions($client); |
|
92 | - $client->request('GET', '/', []); |
|
93 | - $client->getResponse()->getContent(); |
|
94 | - } |
|
95 | - |
|
96 | - public function testEndpointWithEmptyPostJsonBodyQuery(): void |
|
97 | - { |
|
98 | - $this->expectException(BadRequestHttpException::class); |
|
99 | - $this->expectExceptionMessage('The request content body must not be empty when using json content type request.'); |
|
100 | - $client = self::createClient(); |
|
101 | - $this->disableCatchExceptions($client); |
|
102 | - $client->request('POST', '/', [], [], ['CONTENT_TYPE' => 'application/json']); |
|
103 | - } |
|
104 | - |
|
105 | - public function testEndpointWithJsonContentTypeAndGetQuery(): void |
|
106 | - { |
|
107 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
108 | - $this->disableCatchExceptions($client); |
|
109 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/json']); |
|
110 | - $result = $client->getResponse()->getContent(); |
|
111 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
112 | - } |
|
113 | - |
|
114 | - public function testEndpointWithInvalidBodyQuery(): void |
|
115 | - { |
|
116 | - $this->expectException(BadRequestHttpException::class); |
|
117 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
118 | - $client = self::createClient(); |
|
119 | - $this->disableCatchExceptions($client); |
|
120 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
121 | - $client->getResponse()->getContent(); |
|
122 | - } |
|
123 | - |
|
124 | - public function testEndpointActionWithVariables(): void |
|
125 | - { |
|
126 | - $client = self::createClient(['test_case' => 'connection']); |
|
127 | - $this->disableCatchExceptions($client); |
|
128 | - |
|
129 | - $query = <<<'EOF' |
|
130 | - query FriendsQuery($firstFriends: Int) { |
|
131 | - user { |
|
132 | - friends(first: $firstFriends) { |
|
133 | - totalCount |
|
134 | - edges { |
|
135 | - friendshipTime |
|
136 | - node { |
|
137 | - name |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - EOF; |
|
144 | - |
|
145 | - $content = json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']) ?: null; |
|
146 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
147 | - $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
148 | - } |
|
149 | - |
|
150 | - public function testEndpointActionWithInvalidVariables(): void |
|
151 | - { |
|
152 | - $this->expectException(BadRequestHttpException::class); |
|
153 | - $this->expectExceptionMessage('Variables are invalid JSON'); |
|
154 | - $client = self::createClient(['test_case' => 'connection']); |
|
155 | - $this->disableCatchExceptions($client); |
|
156 | - |
|
157 | - $query = <<<'EOF' |
|
158 | - query { |
|
159 | - user |
|
160 | - } |
|
161 | - EOF; |
|
162 | - |
|
163 | - $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']); |
|
164 | - } |
|
165 | - |
|
166 | - public function testMultipleEndpointActionWithUnknownSchemaName(): void |
|
167 | - { |
|
168 | - $this->expectException(NotFoundHttpException::class); |
|
169 | - $this->expectExceptionMessage('Could not find "fake" schema.'); |
|
170 | - $client = self::createClient(['test_case' => 'connection']); |
|
171 | - $this->disableCatchExceptions($client); |
|
172 | - |
|
173 | - $query = <<<'EOF' |
|
174 | - query { |
|
175 | - user |
|
176 | - } |
|
177 | - EOF; |
|
178 | - |
|
179 | - $client->request('GET', '/graphql/fake', ['query' => $query]); |
|
180 | - } |
|
181 | - |
|
182 | - public function testEndpointActionWithOperationName(): void |
|
183 | - { |
|
184 | - $client = self::createClient(['test_case' => 'connection']); |
|
185 | - $this->disableCatchExceptions($client); |
|
186 | - |
|
187 | - $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery; |
|
188 | - |
|
189 | - $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']); |
|
190 | - $result = $client->getResponse()->getContent(); |
|
191 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @dataProvider graphQLBatchEndpointUriProvider |
|
196 | - */ |
|
197 | - public function testBatchEndpointAction(string $uri): void |
|
198 | - { |
|
199 | - $client = self::createClient(['test_case' => 'connection']); |
|
200 | - $this->disableCatchExceptions($client); |
|
201 | - |
|
202 | - $data = [ |
|
203 | - [ |
|
204 | - 'id' => 'friends', |
|
205 | - 'query' => $this->friendsQuery, |
|
206 | - ], |
|
207 | - [ |
|
208 | - 'id' => 'friendsTotalCount', |
|
209 | - 'query' => $this->friendsTotalCountQuery, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - |
|
213 | - $content = json_encode($data) ?: null; |
|
214 | - $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
215 | - $result = $client->getResponse()->getContent(); |
|
216 | - |
|
217 | - $expected = [ |
|
218 | - ['id' => 'friends', 'payload' => ['data' => $this->expectedData]], |
|
219 | - ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]], |
|
220 | - ]; |
|
221 | - $this->assertSame($expected, json_decode($result, true), $result); |
|
222 | - } |
|
223 | - |
|
224 | - public function graphQLBatchEndpointUriProvider(): array |
|
225 | - { |
|
226 | - return [ |
|
227 | - ['/batch'], |
|
228 | - ['/graphql/default/batch'], |
|
229 | - ]; |
|
230 | - } |
|
231 | - |
|
232 | - public function testBatchEndpointWithEmptyQuery(): void |
|
233 | - { |
|
234 | - $this->expectException(BadRequestHttpException::class); |
|
235 | - $this->expectExceptionMessage('Must provide at least one valid query.'); |
|
236 | - $client = self::createClient(); |
|
237 | - $this->disableCatchExceptions($client); |
|
238 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
|
239 | - $client->getResponse()->getContent(); |
|
240 | - } |
|
241 | - |
|
242 | - public function testBatchEndpointWrongContentType(): void |
|
243 | - { |
|
244 | - $this->expectException(BadRequestHttpException::class); |
|
245 | - $this->expectExceptionMessage('Batching parser only accepts "application/json" or "multipart/form-data" content-type but got "".'); |
|
246 | - $client = self::createClient(); |
|
247 | - $this->disableCatchExceptions($client); |
|
248 | - $client->request('GET', '/batch'); |
|
249 | - $client->getResponse()->getContent(); |
|
250 | - } |
|
251 | - |
|
252 | - public function testBatchEndpointWithInvalidJson(): void |
|
253 | - { |
|
254 | - $this->expectException(BadRequestHttpException::class); |
|
255 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
256 | - $client = self::createClient(); |
|
257 | - $this->disableCatchExceptions($client); |
|
258 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
259 | - $client->getResponse()->getContent(); |
|
260 | - } |
|
261 | - |
|
262 | - public function testBatchEndpointWithInvalidQuery(): void |
|
263 | - { |
|
264 | - $this->expectException(BadRequestHttpException::class); |
|
265 | - $this->expectExceptionMessage('1 is not a valid query'); |
|
266 | - $client = self::createClient(); |
|
267 | - $this->disableCatchExceptions($client); |
|
268 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}'); |
|
269 | - $client->getResponse()->getContent(); |
|
270 | - } |
|
271 | - |
|
272 | - public function testPreflightedRequestWhenDisabled(): void |
|
273 | - { |
|
274 | - $client = self::createClient(['test_case' => 'connection']); |
|
275 | - $this->disableCatchExceptions($client); |
|
276 | - $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
277 | - $response = $client->getResponse(); |
|
278 | - $this->assertSame(200, $response->getStatusCode()); |
|
279 | - $this->assertCORSHeadersNotExists($client); |
|
280 | - } |
|
281 | - |
|
282 | - public function testUnAuthorizedMethod(): void |
|
283 | - { |
|
284 | - $client = self::createClient(['test_case' => 'connection']); |
|
285 | - $this->disableCatchExceptions($client); |
|
286 | - $client->request('PUT', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
287 | - $this->assertSame(405, $client->getResponse()->getStatusCode()); |
|
288 | - } |
|
289 | - |
|
290 | - public function testPreflightedRequestWhenEnabled(): void |
|
291 | - { |
|
292 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
293 | - $this->disableCatchExceptions($client); |
|
294 | - $client->request('OPTIONS', '/batch', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
295 | - $this->assertCORSHeadersExists($client); |
|
296 | - } |
|
297 | - |
|
298 | - public function testNoCORSHeadersIfOriginHeaderNotExists(): void |
|
299 | - { |
|
300 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
301 | - $this->disableCatchExceptions($client); |
|
302 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']); |
|
303 | - $result = $client->getResponse()->getContent(); |
|
304 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
305 | - $this->assertCORSHeadersNotExists($client); |
|
306 | - } |
|
307 | - |
|
308 | - private function assertCORSHeadersNotExists(KernelBrowser $client): void |
|
309 | - { |
|
310 | - $headers = $client->getResponse()->headers->all(); |
|
311 | - $this->assertArrayNotHasKey('access-control-allow-origin', $headers); |
|
312 | - $this->assertArrayNotHasKey('access-control-allow-methods', $headers); |
|
313 | - $this->assertArrayNotHasKey('access-control-allow-credentials', $headers); |
|
314 | - $this->assertArrayNotHasKey('access-control-allow-headers', $headers); |
|
315 | - $this->assertArrayNotHasKey('access-control-max-age', $headers); |
|
316 | - } |
|
317 | - |
|
318 | - private function assertCORSHeadersExists(KernelBrowser $client): void |
|
319 | - { |
|
320 | - $response = $client->getResponse(); |
|
321 | - $this->assertSame(200, $response->getStatusCode()); |
|
322 | - $this->assertSame('http://example.com', $response->headers->get('Access-Control-Allow-Origin')); |
|
323 | - $this->assertSame('OPTIONS, GET, POST', $response->headers->get('Access-Control-Allow-Methods')); |
|
324 | - $this->assertSame('true', $response->headers->get('Access-Control-Allow-Credentials')); |
|
325 | - $this->assertSame('Content-Type, Authorization', $response->headers->get('Access-Control-Allow-Headers')); |
|
326 | - $this->assertSame('3600', $response->headers->get('Access-Control-Max-Age')); |
|
327 | - } |
|
328 | -} |
@@ -14,315 +14,3 @@ |
||
14 | 14 | final class GraphControllerTest extends TestCase |
15 | 15 | { |
16 | 16 | private string $friendsQuery = <<<'EOF' |
17 | - query FriendsQuery { |
|
18 | - user { |
|
19 | - friends(first: 2) { |
|
20 | - totalCount |
|
21 | - edges { |
|
22 | - friendshipTime |
|
23 | - node { |
|
24 | - name |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
28 | - } |
|
29 | - } |
|
30 | - EOF; |
|
31 | - |
|
32 | - private string $friendsTotalCountQuery = <<<'EOF' |
|
33 | - query FriendsTotalCountQuery { |
|
34 | - user { |
|
35 | - friends { |
|
36 | - totalCount |
|
37 | - } |
|
38 | - } |
|
39 | - } |
|
40 | - EOF; |
|
41 | - |
|
42 | - private array $expectedData = [ |
|
43 | - 'user' => [ |
|
44 | - 'friends' => [ |
|
45 | - 'totalCount' => 4, |
|
46 | - 'edges' => [ |
|
47 | - [ |
|
48 | - 'friendshipTime' => 'Yesterday', |
|
49 | - 'node' => [ |
|
50 | - 'name' => 'Nick', |
|
51 | - ], |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'friendshipTime' => 'Yesterday', |
|
55 | - 'node' => [ |
|
56 | - 'name' => 'Lee', |
|
57 | - ], |
|
58 | - ], |
|
59 | - ], |
|
60 | - ], |
|
61 | - ], |
|
62 | - ]; |
|
63 | - |
|
64 | - /** |
|
65 | - * @dataProvider graphQLEndpointUriProvider |
|
66 | - */ |
|
67 | - public function testEndpointAction(string $uri): void |
|
68 | - { |
|
69 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
70 | - $this->disableCatchExceptions($client); |
|
71 | - |
|
72 | - $client->request('GET', $uri, ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql;charset=utf8', 'HTTP_Origin' => 'http://example.com']); |
|
73 | - $result = $client->getResponse()->getContent(); |
|
74 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
75 | - $this->assertCORSHeadersExists($client); |
|
76 | - } |
|
77 | - |
|
78 | - public function graphQLEndpointUriProvider(): array |
|
79 | - { |
|
80 | - return [ |
|
81 | - ['/'], |
|
82 | - ['/graphql/default'], |
|
83 | - ]; |
|
84 | - } |
|
85 | - |
|
86 | - public function testEndpointWithEmptyQuery(): void |
|
87 | - { |
|
88 | - $this->expectException(BadRequestHttpException::class); |
|
89 | - $this->expectExceptionMessage('Must provide query parameter'); |
|
90 | - $client = self::createClient(); |
|
91 | - $this->disableCatchExceptions($client); |
|
92 | - $client->request('GET', '/', []); |
|
93 | - $client->getResponse()->getContent(); |
|
94 | - } |
|
95 | - |
|
96 | - public function testEndpointWithEmptyPostJsonBodyQuery(): void |
|
97 | - { |
|
98 | - $this->expectException(BadRequestHttpException::class); |
|
99 | - $this->expectExceptionMessage('The request content body must not be empty when using json content type request.'); |
|
100 | - $client = self::createClient(); |
|
101 | - $this->disableCatchExceptions($client); |
|
102 | - $client->request('POST', '/', [], [], ['CONTENT_TYPE' => 'application/json']); |
|
103 | - } |
|
104 | - |
|
105 | - public function testEndpointWithJsonContentTypeAndGetQuery(): void |
|
106 | - { |
|
107 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
108 | - $this->disableCatchExceptions($client); |
|
109 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/json']); |
|
110 | - $result = $client->getResponse()->getContent(); |
|
111 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
112 | - } |
|
113 | - |
|
114 | - public function testEndpointWithInvalidBodyQuery(): void |
|
115 | - { |
|
116 | - $this->expectException(BadRequestHttpException::class); |
|
117 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
118 | - $client = self::createClient(); |
|
119 | - $this->disableCatchExceptions($client); |
|
120 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
121 | - $client->getResponse()->getContent(); |
|
122 | - } |
|
123 | - |
|
124 | - public function testEndpointActionWithVariables(): void |
|
125 | - { |
|
126 | - $client = self::createClient(['test_case' => 'connection']); |
|
127 | - $this->disableCatchExceptions($client); |
|
128 | - |
|
129 | - $query = <<<'EOF' |
|
130 | - query FriendsQuery($firstFriends: Int) { |
|
131 | - user { |
|
132 | - friends(first: $firstFriends) { |
|
133 | - totalCount |
|
134 | - edges { |
|
135 | - friendshipTime |
|
136 | - node { |
|
137 | - name |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - EOF; |
|
144 | - |
|
145 | - $content = json_encode(['query' => $query, 'variables' => '{"firstFriends": 2}']) ?: null; |
|
146 | - $client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
147 | - $this->assertSame(200, $client->getResponse()->getStatusCode()); |
|
148 | - } |
|
149 | - |
|
150 | - public function testEndpointActionWithInvalidVariables(): void |
|
151 | - { |
|
152 | - $this->expectException(BadRequestHttpException::class); |
|
153 | - $this->expectExceptionMessage('Variables are invalid JSON'); |
|
154 | - $client = self::createClient(['test_case' => 'connection']); |
|
155 | - $this->disableCatchExceptions($client); |
|
156 | - |
|
157 | - $query = <<<'EOF' |
|
158 | - query { |
|
159 | - user |
|
160 | - } |
|
161 | - EOF; |
|
162 | - |
|
163 | - $client->request('GET', '/', ['query' => $query, 'variables' => '"firstFriends": 2}']); |
|
164 | - } |
|
165 | - |
|
166 | - public function testMultipleEndpointActionWithUnknownSchemaName(): void |
|
167 | - { |
|
168 | - $this->expectException(NotFoundHttpException::class); |
|
169 | - $this->expectExceptionMessage('Could not find "fake" schema.'); |
|
170 | - $client = self::createClient(['test_case' => 'connection']); |
|
171 | - $this->disableCatchExceptions($client); |
|
172 | - |
|
173 | - $query = <<<'EOF' |
|
174 | - query { |
|
175 | - user |
|
176 | - } |
|
177 | - EOF; |
|
178 | - |
|
179 | - $client->request('GET', '/graphql/fake', ['query' => $query]); |
|
180 | - } |
|
181 | - |
|
182 | - public function testEndpointActionWithOperationName(): void |
|
183 | - { |
|
184 | - $client = self::createClient(['test_case' => 'connection']); |
|
185 | - $this->disableCatchExceptions($client); |
|
186 | - |
|
187 | - $query = $this->friendsQuery."\n".$this->friendsTotalCountQuery; |
|
188 | - |
|
189 | - $client->request('POST', '/', ['query' => $query, 'operationName' => 'FriendsQuery'], [], ['CONTENT_TYPE' => 'application/x-www-form-urlencoded']); |
|
190 | - $result = $client->getResponse()->getContent(); |
|
191 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @dataProvider graphQLBatchEndpointUriProvider |
|
196 | - */ |
|
197 | - public function testBatchEndpointAction(string $uri): void |
|
198 | - { |
|
199 | - $client = self::createClient(['test_case' => 'connection']); |
|
200 | - $this->disableCatchExceptions($client); |
|
201 | - |
|
202 | - $data = [ |
|
203 | - [ |
|
204 | - 'id' => 'friends', |
|
205 | - 'query' => $this->friendsQuery, |
|
206 | - ], |
|
207 | - [ |
|
208 | - 'id' => 'friendsTotalCount', |
|
209 | - 'query' => $this->friendsTotalCountQuery, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - |
|
213 | - $content = json_encode($data) ?: null; |
|
214 | - $client->request('POST', $uri, [], [], ['CONTENT_TYPE' => 'application/json'], $content); |
|
215 | - $result = $client->getResponse()->getContent(); |
|
216 | - |
|
217 | - $expected = [ |
|
218 | - ['id' => 'friends', 'payload' => ['data' => $this->expectedData]], |
|
219 | - ['id' => 'friendsTotalCount', 'payload' => ['data' => ['user' => ['friends' => ['totalCount' => 4]]]]], |
|
220 | - ]; |
|
221 | - $this->assertSame($expected, json_decode($result, true), $result); |
|
222 | - } |
|
223 | - |
|
224 | - public function graphQLBatchEndpointUriProvider(): array |
|
225 | - { |
|
226 | - return [ |
|
227 | - ['/batch'], |
|
228 | - ['/graphql/default/batch'], |
|
229 | - ]; |
|
230 | - } |
|
231 | - |
|
232 | - public function testBatchEndpointWithEmptyQuery(): void |
|
233 | - { |
|
234 | - $this->expectException(BadRequestHttpException::class); |
|
235 | - $this->expectExceptionMessage('Must provide at least one valid query.'); |
|
236 | - $client = self::createClient(); |
|
237 | - $this->disableCatchExceptions($client); |
|
238 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{}'); |
|
239 | - $client->getResponse()->getContent(); |
|
240 | - } |
|
241 | - |
|
242 | - public function testBatchEndpointWrongContentType(): void |
|
243 | - { |
|
244 | - $this->expectException(BadRequestHttpException::class); |
|
245 | - $this->expectExceptionMessage('Batching parser only accepts "application/json" or "multipart/form-data" content-type but got "".'); |
|
246 | - $client = self::createClient(); |
|
247 | - $this->disableCatchExceptions($client); |
|
248 | - $client->request('GET', '/batch'); |
|
249 | - $client->getResponse()->getContent(); |
|
250 | - } |
|
251 | - |
|
252 | - public function testBatchEndpointWithInvalidJson(): void |
|
253 | - { |
|
254 | - $this->expectException(BadRequestHttpException::class); |
|
255 | - $this->expectExceptionMessage('POST body sent invalid JSON'); |
|
256 | - $client = self::createClient(); |
|
257 | - $this->disableCatchExceptions($client); |
|
258 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{'); |
|
259 | - $client->getResponse()->getContent(); |
|
260 | - } |
|
261 | - |
|
262 | - public function testBatchEndpointWithInvalidQuery(): void |
|
263 | - { |
|
264 | - $this->expectException(BadRequestHttpException::class); |
|
265 | - $this->expectExceptionMessage('1 is not a valid query'); |
|
266 | - $client = self::createClient(); |
|
267 | - $this->disableCatchExceptions($client); |
|
268 | - $client->request('GET', '/batch', [], [], ['CONTENT_TYPE' => 'application/json'], '{"test" : {"query": 1}}'); |
|
269 | - $client->getResponse()->getContent(); |
|
270 | - } |
|
271 | - |
|
272 | - public function testPreflightedRequestWhenDisabled(): void |
|
273 | - { |
|
274 | - $client = self::createClient(['test_case' => 'connection']); |
|
275 | - $this->disableCatchExceptions($client); |
|
276 | - $client->request('OPTIONS', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
277 | - $response = $client->getResponse(); |
|
278 | - $this->assertSame(200, $response->getStatusCode()); |
|
279 | - $this->assertCORSHeadersNotExists($client); |
|
280 | - } |
|
281 | - |
|
282 | - public function testUnAuthorizedMethod(): void |
|
283 | - { |
|
284 | - $client = self::createClient(['test_case' => 'connection']); |
|
285 | - $this->disableCatchExceptions($client); |
|
286 | - $client->request('PUT', '/', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
287 | - $this->assertSame(405, $client->getResponse()->getStatusCode()); |
|
288 | - } |
|
289 | - |
|
290 | - public function testPreflightedRequestWhenEnabled(): void |
|
291 | - { |
|
292 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
293 | - $this->disableCatchExceptions($client); |
|
294 | - $client->request('OPTIONS', '/batch', [], [], ['HTTP_Origin' => 'http://example.com']); |
|
295 | - $this->assertCORSHeadersExists($client); |
|
296 | - } |
|
297 | - |
|
298 | - public function testNoCORSHeadersIfOriginHeaderNotExists(): void |
|
299 | - { |
|
300 | - $client = self::createClient(['test_case' => 'connectionWithCORS']); |
|
301 | - $this->disableCatchExceptions($client); |
|
302 | - $client->request('GET', '/', ['query' => $this->friendsQuery], [], ['CONTENT_TYPE' => 'application/graphql']); |
|
303 | - $result = $client->getResponse()->getContent(); |
|
304 | - $this->assertSame(['data' => $this->expectedData], json_decode($result, true), $result); |
|
305 | - $this->assertCORSHeadersNotExists($client); |
|
306 | - } |
|
307 | - |
|
308 | - private function assertCORSHeadersNotExists(KernelBrowser $client): void |
|
309 | - { |
|
310 | - $headers = $client->getResponse()->headers->all(); |
|
311 | - $this->assertArrayNotHasKey('access-control-allow-origin', $headers); |
|
312 | - $this->assertArrayNotHasKey('access-control-allow-methods', $headers); |
|
313 | - $this->assertArrayNotHasKey('access-control-allow-credentials', $headers); |
|
314 | - $this->assertArrayNotHasKey('access-control-allow-headers', $headers); |
|
315 | - $this->assertArrayNotHasKey('access-control-max-age', $headers); |
|
316 | - } |
|
317 | - |
|
318 | - private function assertCORSHeadersExists(KernelBrowser $client): void |
|
319 | - { |
|
320 | - $response = $client->getResponse(); |
|
321 | - $this->assertSame(200, $response->getStatusCode()); |
|
322 | - $this->assertSame('http://example.com', $response->headers->get('Access-Control-Allow-Origin')); |
|
323 | - $this->assertSame('OPTIONS, GET, POST', $response->headers->get('Access-Control-Allow-Methods')); |
|
324 | - $this->assertSame('true', $response->headers->get('Access-Control-Allow-Credentials')); |
|
325 | - $this->assertSame('Content-Type, Authorization', $response->headers->get('Access-Control-Allow-Headers')); |
|
326 | - $this->assertSame('3600', $response->headers->get('Access-Control-Max-Age')); |
|
327 | - } |
|
328 | -} |