1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle 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\GraphQLBundle\Tests\Resolver; |
13
|
|
|
|
14
|
|
|
use GraphQL\Schema; |
15
|
|
|
use GraphQL\Type\Definition\ObjectType; |
16
|
|
|
use GraphQL\Type\Definition\Type; |
17
|
|
|
use Overblog\GraphQLBundle\Request\Executor; |
18
|
|
|
|
19
|
|
|
class ExecutorTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
/** @var Executor */ |
22
|
|
|
private $executor; |
23
|
|
|
|
24
|
|
|
private $request = ['query' => 'query debug{ myField }', 'variables' => [], 'operationName' => null]; |
25
|
|
|
|
26
|
|
|
public function setUp() |
27
|
|
|
{ |
28
|
|
|
$this->executor = new Executor(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testDisabledDebugInfo() |
32
|
|
|
{ |
33
|
|
|
$this->addSchema(); |
34
|
|
|
$this->assertArrayNotHasKey('debug', $this->executor->disabledDebugInfo()->execute($this->request)->extensions); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testEnabledDebugInfo() |
38
|
|
|
{ |
39
|
|
|
$this->addSchema(); |
40
|
|
|
$result = $this->executor->enabledDebugInfo()->execute($this->request); |
41
|
|
|
|
42
|
|
|
$this->assertArrayHasKey('debug', $result->extensions); |
43
|
|
|
$this->assertArrayHasKey('executionTime', $result->extensions['debug']); |
44
|
|
|
$this->assertArrayHasKey('memoryUsage', $result->extensions['debug']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @expectedException \RuntimeException |
49
|
|
|
* @expectedExceptionMessage At least one schema should be declare. |
50
|
|
|
*/ |
51
|
|
|
public function testGetSchemaNoSchemaFound() |
52
|
|
|
{ |
53
|
|
|
$this->executor->getSchema('fake'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function addSchema() |
57
|
|
|
{ |
58
|
|
|
$queryType = new ObjectType([ |
59
|
|
|
'name' => 'Query', |
60
|
|
|
'fields' => [ |
61
|
|
|
'myField' => [ |
62
|
|
|
'type' => Type::boolean(), |
63
|
|
|
'resolve' => function () { |
64
|
|
|
return false; |
65
|
|
|
}, |
66
|
|
|
], |
67
|
|
|
], |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
$this->executor->addSchema('global', new Schema(['query' => $queryType])); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|