Skip to content

Commit

Permalink
test(APQ): Simplify dynamic page cache test code
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi committed Apr 6, 2024
1 parent 53eb21e commit eb832b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/EventSubscriber/ApqSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function onBeforeOperation(OperationEvent $event): void {
// Add cache context for dynamic page cache compatibility on all
// operations that have the hash set.
$event->getContext()->addCacheContexts(
//['url.query_args']
['url.query_args:variables', 'url.query_args:extensions']
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\HttpFoundation\Request;

/**
* Tests the automatic persisted query plugin.
* Tests the APQ plugin in combination with dynamic page cache.
*
* @group graphql
*/
Expand Down Expand Up @@ -108,31 +108,32 @@ public function testPageCacheWithDifferentVariables(): void {
$idQuery = 'query($id: String!) { node(id: $id) { id } }';

// Post query to endpoint to register the query hashes.
$parameters['extensions']['persistedQuery']['sha256Hash'] = hash('sha256', $titleQuery);
$parameters['variables'] = '{"id": "2"}';
$content = json_encode(['query' => $titleQuery] + $parameters);
$request = Request::create($endpoint, 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], $content);
$result = $this->container->get('http_kernel')->handle($request);
$extensions['persistedQuery']['sha256Hash'] = hash('sha256', $titleQuery);
$variables = ['id' => '2'];
$result = $this->query($titleQuery, $this->server, $variables, $extensions, FALSE, Request::METHOD_POST);
$this->assertSame(200, $result->getStatusCode());
$this->assertSame(['data' => ['node' => ['title' => 'Node 2']]], json_decode($result->getContent(), TRUE));

$parameters['extensions']['persistedQuery']['sha256Hash'] = hash('sha256', $idQuery);
$parameters['variables'] = '{"id": "2"}';
$content = json_encode(['query' => $idQuery] + $parameters);
$request = Request::create($endpoint, 'POST', [], [], [], ['CONTENT_TYPE' => 'application/json'], $content);
$result = $this->container->get('http_kernel')->handle($request);
$extensions['persistedQuery']['sha256Hash'] = hash('sha256', $idQuery);
$variables = ['id' => '2'];
$result = $this->query($idQuery, $this->server, $variables, $extensions, FALSE, Request::METHOD_POST);
$this->assertSame(200, $result->getStatusCode());
$this->assertSame(['data' => ['node' => ['id' => 2]]], json_decode($result->getContent(), TRUE));

// Execute apq call.
$parameters['variables'] = '{"id": "1"}';
/*$parameters['extensions']['persistedQuery']['sha256Hash'] = hash('sha256', $idQuery);
$parameters['variables'] = ['id' => '1'];
$request = Request::create($endpoint, 'GET', $parameters);
$result = $this->container->get('http_kernel')->handle($request);
$result = $this->container->get('http_kernel')->handle($request);*/

$variables = ['id' => '1'];
$this->query($idQuery, $this->server, $variables, $extensions);

$this->assertSame(200, $result->getStatusCode());
$this->assertSame(['data' => ['node' => ['id' => 1]]], json_decode($result->getContent(), TRUE));

// Execute apq call with different variables.
$parameters['variables'] = '{"id": "2"}';
/*$parameters['variables'] = '{"id": "2"}';
$request = Request::create($endpoint, 'GET', $parameters);
$result = $this->container->get('http_kernel')->handle($request);
$this->assertSame(200, $result->getStatusCode());
Expand All @@ -144,7 +145,7 @@ public function testPageCacheWithDifferentVariables(): void {
$request = Request::create($endpoint, 'GET', $parameters);
$result = $this->container->get('http_kernel')->handle($request);
$this->assertSame(200, $result->getStatusCode());
$this->assertSame(['data' => ['node' => ['title' => 'Node 2']]], json_decode($result->getContent(), TRUE));
$this->assertSame(['data' => ['node' => ['title' => 'Node 2']]], json_decode($result->getContent(), TRUE));*/

}

Expand Down

0 comments on commit eb832b4

Please sign in to comment.