From 371176249deb1ed4938879903e6d1ec69e351607 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sat, 6 Apr 2024 17:54:02 +0200 Subject: [PATCH] test(APQ): Simplify test case by using query helper method (#1393) --- .../AutomaticPersistedQueriesTest.php | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/src/Kernel/Framework/AutomaticPersistedQueriesTest.php b/tests/src/Kernel/Framework/AutomaticPersistedQueriesTest.php index 6a8ad512f..873eb777d 100644 --- a/tests/src/Kernel/Framework/AutomaticPersistedQueriesTest.php +++ b/tests/src/Kernel/Framework/AutomaticPersistedQueriesTest.php @@ -52,14 +52,12 @@ public function testAutomaticPersistedQueries(): void { $this->server->addPersistedQueryInstance($this->pluginApq); $this->server->save(); - $endpoint = $this->server->get('endpoint'); - $query = 'query { field_one } '; - $parameters['extensions']['persistedQuery']['sha256Hash'] = 'some random hash'; + $extensions = ['persistedQuery' => ['sha256Hash' => 'some random hash']]; // Check we get PersistedQueryNotFound. - $request = Request::create($endpoint, 'GET', $parameters); - $result = $this->container->get('http_kernel')->handle($request); + $result = $this->query('', $this->server, [], $extensions); + $this->assertSame(200, $result->getStatusCode()); $this->assertSame([ 'errors' => [ @@ -71,9 +69,8 @@ public function testAutomaticPersistedQueries(): void { ], json_decode($result->getContent(), TRUE)); // Post query to endpoint with a not matching hash. - $content = json_encode(['query' => $query] + $parameters); - $request = Request::create($endpoint, 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], $content); - $result = $this->container->get('http_kernel')->handle($request); + $result = $this->query($query, $this->server, [], $extensions, FALSE, Request::METHOD_POST); + $this->assertSame(200, $result->getStatusCode()); $this->assertSame([ 'errors' => [ @@ -85,17 +82,14 @@ public function testAutomaticPersistedQueries(): void { ], json_decode($result->getContent(), TRUE)); // Post query to endpoint to get the result and cache it. - $parameters['extensions']['persistedQuery']['sha256Hash'] = hash('sha256', $query); + $extensions['persistedQuery']['sha256Hash'] = hash('sha256', $query); + $result = $this->query($query, $this->server, [], $extensions, FALSE, Request::METHOD_POST); - $content = json_encode(['query' => $query] + $parameters); - $request = Request::create($endpoint, 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], $content); - $result = $this->container->get('http_kernel')->handle($request); $this->assertSame(200, $result->getStatusCode()); $this->assertSame(['data' => ['field_one' => 'this is the field one']], json_decode($result->getContent(), TRUE)); - // Execute first request again. - $request = Request::create($endpoint, 'GET', $parameters); - $result = $this->container->get('http_kernel')->handle($request); + // Execute first GET request again. + $result = $this->query($query, $this->server, [], $extensions); $this->assertSame(200, $result->getStatusCode()); $this->assertSame(['data' => ['field_one' => 'this is the field one']], json_decode($result->getContent(), TRUE)); }