1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLPhpGenerator package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLGenerator\Tests; |
13
|
|
|
|
14
|
|
|
use GraphQL\Error\Debug; |
15
|
|
|
use GraphQL\GraphQL; |
16
|
|
|
use GraphQL\Type\Schema; |
17
|
|
|
use Overblog\GraphQLGenerator\Tests\Generator\AbstractTypeGeneratorTest; |
18
|
|
|
|
19
|
|
|
abstract class AbstractStarWarsTest extends AbstractTypeGeneratorTest |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Schema |
23
|
|
|
*/ |
24
|
|
|
protected $schema; |
25
|
|
|
|
26
|
|
|
public function setUp() |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$this->classLoader->setPsr4('GraphQL\\Tests\\', __DIR__.'/../vendor/webonyx/graphql-php/tests'); |
31
|
|
|
|
32
|
|
|
$this->generateClasses(); |
33
|
|
|
|
34
|
|
|
Resolver::setHumanType($this->getType('Human')); |
35
|
|
|
Resolver::setDroidType($this->getType('Droid')); |
36
|
|
|
|
37
|
|
|
$this->schema = new Schema(['query' => $this->getType('Query')]); |
38
|
|
|
$this->schema->assertValid(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Helper function to test a query and the expected response. |
43
|
|
|
* @param $query |
44
|
|
|
* @param $expected |
45
|
|
|
* @param null $variables |
|
|
|
|
46
|
|
|
*/ |
47
|
|
|
protected function assertValidQuery($query, $expected, $variables = null) |
48
|
|
|
{ |
49
|
|
|
$actual = GraphQL::executeQuery($this->schema, $query, null, null, $variables) |
50
|
|
|
->toArray(Debug::INCLUDE_DEBUG_MESSAGE | Debug::INCLUDE_TRACE); |
51
|
|
|
$expected = ['data' => $expected]; |
52
|
|
|
$this->assertEquals($expected, $actual, \json_encode($actual)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function sortSchemaEntry(array &$entries, $entryKey, $sortBy) |
56
|
|
|
{ |
57
|
|
|
if (isset($entries['data']['__schema'][$entryKey])) { |
58
|
|
|
$data = &$entries['data']['__schema'][$entryKey]; |
59
|
|
|
} else { |
60
|
|
|
$data = &$entries['__schema'][$entryKey]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
\usort($data, function ($data1, $data2) use ($sortBy) { |
64
|
|
|
return \strcmp($data1[$sortBy], $data2[$sortBy]); |
65
|
|
|
}); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|