Skip to content

Commit 03af0fe

Browse files
committed
Add tests for JSON Exceptions
1 parent 8611016 commit 03af0fe

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/FunctionalTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ public function testErrors(): void
104104
$kernel = new GraphQLiteTestingKernel();
105105
$kernel->boot();
106106

107+
$request = Request::create('/graphql', 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], '{"query":"{ invalidJsonSyntax }"');
108+
109+
$response = $kernel->handle($request);
110+
111+
$this->assertSame(415, $response->getStatusCode());
112+
113+
$result = json_decode($response->getContent(), true);
114+
115+
$this->assertSame('Invalid JSON.', $result['errors'][0]['message']);
116+
$this->assertSame('Syntax error', $result['errors'][0]['extensions']['reason']);
117+
118+
$request = Request::create('/graphql', 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], '"Unexpected Json Content"');
119+
120+
$response = $kernel->handle($request);
121+
122+
$this->assertSame(422, $response->getStatusCode());
123+
124+
$result = json_decode($response->getContent(), true);
125+
126+
$this->assertSame('Invalid JSON.', $result['errors'][0]['message']);
127+
$this->assertSame('Expecting associative array from request, got string', $result['errors'][0]['extensions']['reason']);
128+
107129
$request = Request::create('/graphql', 'GET', ['query' => '
108130
{
109131
notExists

0 commit comments

Comments
 (0)