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
|
|
|
$queryType = new ObjectType([ |
30
|
|
|
'name' => 'Query', |
31
|
|
|
'fields' => [ |
32
|
|
|
'myField' => [ |
33
|
|
|
'type' => Type::boolean(), |
34
|
|
|
'resolve' => function () { |
35
|
|
|
return false; |
36
|
|
|
}, |
37
|
|
|
], |
38
|
|
|
], |
39
|
|
|
]); |
40
|
|
|
$this->executor->addSchema('global', new Schema(['query' => $queryType])); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException \RuntimeException |
45
|
|
|
* @expectedExceptionMessage Execution result should be an object instantiating "GraphQL\Executor\ExecutionResult". |
46
|
|
|
*/ |
47
|
|
|
public function testInvalidExecutorReturnNotObject() |
48
|
|
|
{ |
49
|
|
|
$this->executor->setExecutor(function() { return false; }); |
50
|
|
|
$this->executor->execute($this->request); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @expectedException \RuntimeException |
55
|
|
|
* @expectedExceptionMessage Execution result should be an object instantiating "GraphQL\Executor\ExecutionResult". |
56
|
|
|
*/ |
57
|
|
|
public function testInvalidExecutorReturnInvalidObject() |
58
|
|
|
{ |
59
|
|
|
$this->executor->setExecutor(function() { return new \stdClass(); }); |
60
|
|
|
$this->executor->execute($this->request); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testDisabledDebugInfo() |
64
|
|
|
{ |
65
|
|
|
$this->assertArrayNotHasKey('debug', $this->executor->disabledDebugInfo()->execute($this->request)->extensions); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testEnabledDebugInfo() |
69
|
|
|
{ |
70
|
|
|
$result = $this->executor->enabledDebugInfo()->execute($this->request); |
71
|
|
|
|
72
|
|
|
$this->assertArrayHasKey('debug', $result->extensions); |
73
|
|
|
$this->assertArrayHasKey('executionTime', $result->extensions['debug']); |
74
|
|
|
$this->assertArrayHasKey('memoryUsage', $result->extensions['debug']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @expectedException \RuntimeException |
79
|
|
|
* @expectedExceptionMessage At least one schema should be declare. |
80
|
|
|
*/ |
81
|
|
|
public function testGetSchemaNoSchemaFound() |
82
|
|
|
{ |
83
|
|
|
(new Executor())->getSchema('fake'); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|