You are here

private function QueryResultAssertionTrait::assertResultMetadata in GraphQL 8.4

Same name and namespace in other branches
  1. 8.3 tests/src/Traits/QueryResultAssertionTrait.php \Drupal\Tests\graphql\Traits\QueryResultAssertionTrait::assertResultMetadata()

Assert a certain set of result metadata on a query result.

@internal

Parameters

\Drupal\graphql\GraphQL\Execution\ExecutionResult $result: The query result object.

\Drupal\Core\Cache\CacheableMetadata $expected: The expected metadata object.

2 calls to QueryResultAssertionTrait::assertResultMetadata()
QueryResultAssertionTrait::assertErrors in tests/src/Traits/QueryResultAssertionTrait.php
Assert a query result with certain errors.
QueryResultAssertionTrait::assertResults in tests/src/Traits/QueryResultAssertionTrait.php
Assert a result for a graphql query and variables.

File

tests/src/Traits/QueryResultAssertionTrait.php, line 218

Class

QueryResultAssertionTrait
Trait for easier assertion on GraphQL query results.

Namespace

Drupal\Tests\graphql\Traits

Code

private function assertResultMetadata(ExecutionResult $result, CacheableMetadata $expected) : void {
  $this
    ->assertEquals($expected
    ->getCacheMaxAge(), $result
    ->getCacheMaxAge(), 'Unexpected cache max age.');
  $missingContexts = array_diff($expected
    ->getCacheContexts(), $result
    ->getCacheContexts());
  $this
    ->assertEmpty($missingContexts, 'Missing cache contexts: ' . implode(', ', $missingContexts));
  $unexpectedContexts = array_diff($result
    ->getCacheContexts(), $expected
    ->getCacheContexts());
  $this
    ->assertEmpty($unexpectedContexts, 'Unexpected cache contexts: ' . implode(', ', $unexpectedContexts));
  $missingTags = array_diff($expected
    ->getCacheTags(), $result
    ->getCacheTags());
  $this
    ->assertEmpty($missingTags, 'Missing cache tags: ' . implode(', ', $missingTags));
  $unexpectedTags = array_diff($result
    ->getCacheTags(), $expected
    ->getCacheTags());
  $this
    ->assertEmpty($unexpectedTags, 'Unexpected cache tags: ' . implode(', ', $unexpectedTags));
}