Skip to content

Commit

Permalink
- fixes bug in CompilerPass (#182)
Browse files Browse the repository at this point in the history
- fixes tests

---------

Co-authored-by: asrar <[email protected]> and  @faizanakram99
  • Loading branch information
faizanakram99 authored Aug 29, 2023
1 parent 52582f4 commit 54959bd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
5 changes: 4 additions & 1 deletion DependencyInjection/GraphQLiteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ private static function getParametersByName(ReflectionMethod $method): array
private function getAnnotationReader(): AnnotationReader
{
if ($this->annotationReader === null) {
AnnotationRegistry::registerLoader('class_exists');
// @phpstan-ignore-next-line "registerLoader exists in doctrine/annotations:v1.x"
if (method_exists(AnnotationRegistry::class, 'registerLoader')) {
AnnotationRegistry::registerLoader('class_exists');
}

$doctrineAnnotationReader = new DoctrineAnnotationReader();

Expand Down
56 changes: 46 additions & 10 deletions Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function testInjectQuery(): void
], $result);
}

public function testLoginQuery(): void
public function testLoginQueryWithRequestParams(): void
{
$kernel = new GraphQLiteTestingKernel();
$kernel->boot();
Expand All @@ -247,7 +247,43 @@ public function testLoginQuery(): void
}
'];

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

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

$result = json_decode($response->getContent(), true);

$this->assertSame([
'data' => [
'login' => [
'userName' => 'foo',
'roles' => [
'ROLE_USER'
]
]
]
], $result);
}

public function testLoginQueryWithRequestBody(): void
{
$kernel = new GraphQLiteTestingKernel();
$kernel->boot();

$session = new Session(new MockArraySessionStorage());
$container = $kernel->getContainer();
$container->set('session', $session);

$body = ['query' => '
mutation login {
login(userName: "foo", password: "bar") {
userName
roles
}
}
'];

$request = Request::create('/graphql', 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($body));

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

Expand Down Expand Up @@ -283,7 +319,7 @@ public function testMeQuery(): void
}
'];

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

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

Expand All @@ -310,7 +346,7 @@ public function testNoLoginNoSessionQuery(): void
}
'];

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

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

Expand Down Expand Up @@ -394,7 +430,7 @@ public function testAllOff(): void
}
'];

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

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

Expand All @@ -418,7 +454,7 @@ public function testValidation(): void
}
'];

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

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

Expand All @@ -445,7 +481,7 @@ public function testWithIntrospection(): void
}
'];

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

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

Expand All @@ -470,7 +506,7 @@ public function testDisableIntrospection(): void
}
'];

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

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

Expand Down Expand Up @@ -498,7 +534,7 @@ public function testMaxQueryComplexity(): void
}
'];

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

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

Expand Down Expand Up @@ -532,7 +568,7 @@ public function testMaxQueryDepth(): void
}
'];

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

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

Expand Down

0 comments on commit 54959bd

Please sign in to comment.