You are here

public function ResultCacheTest::testVariables in GraphQL 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/Framework/ResultCacheTest.php \Drupal\Tests\graphql\Kernel\Framework\ResultCacheTest::testVariables()

Test if caching properly handles variables.

File

tests/src/Kernel/Framework/ResultCacheTest.php, line 157

Class

ResultCacheTest
Test query result caching.

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testVariables() : void {
  $dummy = $this
    ->getMockBuilder(Server::class)
    ->disableOriginalConstructor()
    ->setMethods([
    'id',
  ])
    ->getMock();
  $dummy
    ->expects($this
    ->exactly(2))
    ->method('id')
    ->willReturn('test');
  $this
    ->mockResolver('Query', 'root', function () use ($dummy) {
    return $dummy
      ->id();
  });

  // This result will be stored in the cache.
  $this
    ->query('{ root }', NULL, [
    'value' => 'a',
  ]);

  // This will trigger a new evaluation since it passes different variables.
  $this
    ->query('{ root }', NULL, [
    'value' => 'b',
  ]);

  // This should be served from cache.
  $this
    ->query('{ root }', NULL, [
    'value' => 'a',
  ]);
}