You are here

public function TestFrameworkTest::testFieldMock in GraphQL 8.4

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

Test mocked fields.

File

tests/src/Kernel/Framework/TestFrameworkTest.php, line 19

Class

TestFrameworkTest
Test the test framework.

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testFieldMock() : void {
  $schema = <<<GQL
      type Query {
        root: String
      }
GQL;
  $this
    ->setUpSchema($schema);
  $cacheable = $this
    ->getMockBuilder(CacheableDependencyInterface::class)
    ->setMethods([
    'getCacheTags',
    'getCacheMaxAge',
    'getCacheContexts',
  ])
    ->getMock();
  $cacheable
    ->expects($this
    ->any())
    ->method('getCacheTags')
    ->willReturn([
    'my_tag',
  ]);
  $cacheable
    ->expects($this
    ->any())
    ->method('getCacheMaxAge')
    ->willReturn(42);
  $cacheable
    ->expects($this
    ->any())
    ->method('getCacheContexts')
    ->willReturn([]);
  $this
    ->mockResolver('Query', 'root', $this->builder
    ->compose($this->builder
    ->fromValue($cacheable), $this->builder
    ->fromValue('test')));
  $metadata = $this
    ->defaultCacheMetaData();
  $metadata
    ->setCacheMaxAge(42);
  $metadata
    ->addCacheTags([
    'my_tag',
  ]);
  $this
    ->assertResults('{ root }', [], [
    'root' => 'test',
  ], $metadata);
}