You are here

ResultTest.php in GraphQL 8.4

Same filename and directory in other branches
  1. 8.3 tests/src/Kernel/Framework/ResultTest.php

File

tests/src/Kernel/Framework/ResultTest.php
View source
<?php

namespace Drupal\Tests\graphql\Kernel\Framework;

use Drupal\Tests\graphql\Kernel\GraphQLTestBase;

/**
 * Test the whole query result pipeline.
 *
 * @group graphql
 */
class ResultTest extends GraphQLTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $schema = <<<GQL
      schema {
        query: Query
      }
      type Query {
        root: String
      }
GQL;
    $this
      ->setUpSchema($schema);
    $this
      ->mockResolver('Query', 'root', 'test');
  }

  /**
   * Test a simple query result.
   */
  public function testQuery() : void {
    $result = $this
      ->query('query { root }');
    $this
      ->assertSame(200, $result
      ->getStatusCode());
    $this
      ->assertSame([
      'data' => [
        'root' => 'test',
      ],
    ], json_decode($result
      ->getContent(), TRUE));
  }

  /**
   * Test a batched query result.
   */
  public function testBatchedQueries() : void {
    $result = $this
      ->batchedQueries([
      [
        'query' => 'query { root } ',
      ],
      [
        'query' => 'query { root }',
      ],
    ]);
    $this
      ->assertSame(200, $result
      ->getStatusCode());
    $this
      ->assertSame([
      [
        'data' => [
          'root' => 'test',
        ],
      ],
      [
        'data' => [
          'root' => 'test',
        ],
      ],
    ], json_decode($result
      ->getContent(), TRUE));
  }

}

Classes

Namesort descending Description
ResultTest Test the whole query result pipeline.