Skip to content

Commit 54959bd

Browse files
- fixes bug in CompilerPass (#182)
- fixes tests --------- Co-authored-by: asrar <aszenz@gmail.com> and @faizanakram99
1 parent 52582f4 commit 54959bd

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

DependencyInjection/GraphQLiteCompilerPass.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,10 @@ private static function getParametersByName(ReflectionMethod $method): array
429429
private function getAnnotationReader(): AnnotationReader
430430
{
431431
if ($this->annotationReader === null) {
432-
AnnotationRegistry::registerLoader('class_exists');
432+
// @phpstan-ignore-next-line "registerLoader exists in doctrine/annotations:v1.x"
433+
if (method_exists(AnnotationRegistry::class, 'registerLoader')) {
434+
AnnotationRegistry::registerLoader('class_exists');
435+
}
433436

434437
$doctrineAnnotationReader = new DoctrineAnnotationReader();
435438

Tests/FunctionalTest.php

+46-10
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function testInjectQuery(): void
229229
], $result);
230230
}
231231

232-
public function testLoginQuery(): void
232+
public function testLoginQueryWithRequestParams(): void
233233
{
234234
$kernel = new GraphQLiteTestingKernel();
235235
$kernel->boot();
@@ -247,7 +247,43 @@ public function testLoginQuery(): void
247247
}
248248
'];
249249

250-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
250+
$request = Request::create('/graphql', 'POST', $parameters);
251+
252+
$response = $kernel->handle($request);
253+
254+
$result = json_decode($response->getContent(), true);
255+
256+
$this->assertSame([
257+
'data' => [
258+
'login' => [
259+
'userName' => 'foo',
260+
'roles' => [
261+
'ROLE_USER'
262+
]
263+
]
264+
]
265+
], $result);
266+
}
267+
268+
public function testLoginQueryWithRequestBody(): void
269+
{
270+
$kernel = new GraphQLiteTestingKernel();
271+
$kernel->boot();
272+
273+
$session = new Session(new MockArraySessionStorage());
274+
$container = $kernel->getContainer();
275+
$container->set('session', $session);
276+
277+
$body = ['query' => '
278+
mutation login {
279+
login(userName: "foo", password: "bar") {
280+
userName
281+
roles
282+
}
283+
}
284+
'];
285+
286+
$request = Request::create('/graphql', 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($body));
251287

252288
$response = $kernel->handle($request);
253289

@@ -283,7 +319,7 @@ public function testMeQuery(): void
283319
}
284320
'];
285321

286-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
322+
$request = Request::create('/graphql', 'POST', $parameters);
287323

288324
$response = $kernel->handle($request);
289325

@@ -310,7 +346,7 @@ public function testNoLoginNoSessionQuery(): void
310346
}
311347
'];
312348

313-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
349+
$request = Request::create('/graphql', 'POST', $parameters);
314350

315351
$response = $kernel->handle($request);
316352

@@ -394,7 +430,7 @@ public function testAllOff(): void
394430
}
395431
'];
396432

397-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
433+
$request = Request::create('/graphql', 'POST', $parameters);
398434

399435
$response = $kernel->handle($request);
400436

@@ -418,7 +454,7 @@ public function testValidation(): void
418454
}
419455
'];
420456

421-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
457+
$request = Request::create('/graphql', 'POST', $parameters);
422458

423459
$response = $kernel->handle($request);
424460

@@ -445,7 +481,7 @@ public function testWithIntrospection(): void
445481
}
446482
'];
447483

448-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
484+
$request = Request::create('/graphql', 'POST', $parameters);
449485

450486
$response = $kernel->handle($request);
451487

@@ -470,7 +506,7 @@ public function testDisableIntrospection(): void
470506
}
471507
'];
472508

473-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
509+
$request = Request::create('/graphql', 'POST', $parameters);
474510

475511
$response = $kernel->handle($request);
476512

@@ -498,7 +534,7 @@ public function testMaxQueryComplexity(): void
498534
}
499535
'];
500536

501-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
537+
$request = Request::create('/graphql', 'POST', $parameters);
502538

503539
$response = $kernel->handle($request);
504540

@@ -532,7 +568,7 @@ public function testMaxQueryDepth(): void
532568
}
533569
'];
534570

535-
$request = Request::create('/graphql', 'POST', $parameters, [], [], ['CONTENT_TYPE' => 'application/json']);
571+
$request = Request::create('/graphql', 'POST', $parameters);
536572

537573
$response = $kernel->handle($request);
538574

0 commit comments

Comments
 (0)