1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Request; |
4
|
|
|
|
5
|
|
|
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter; |
6
|
|
|
use GraphQL\Type\Definition\ObjectType; |
7
|
|
|
use GraphQL\Type\Definition\Type; |
8
|
|
|
use GraphQL\Type\Schema; |
9
|
|
|
use Overblog\GraphQLBundle\Executor\Executor; |
10
|
|
|
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
13
|
|
|
|
14
|
|
|
class ExecutorTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** @var RequestExecutor */ |
17
|
|
|
private $executor; |
18
|
|
|
|
19
|
|
|
/** @var EventDispatcher|\PHPUnit_Framework_MockObject_MockObject */ |
20
|
|
|
private $dispatcher; |
21
|
|
|
|
22
|
|
|
private $request = ['query' => 'query debug{ myField }', 'variables' => [], 'operationName' => null]; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->dispatcher = $this->getMockBuilder(EventDispatcher::class)->setMethods(['dispatch'])->getMock(); |
27
|
|
|
$this->dispatcher->expects($this->any())->method('dispatch')->willReturnArgument(1); |
28
|
|
|
|
29
|
|
|
$this->executor = new RequestExecutor(new Executor(), $this->dispatcher); |
|
|
|
|
30
|
|
|
$queryType = new ObjectType([ |
31
|
|
|
'name' => 'Query', |
32
|
|
|
'fields' => [ |
33
|
|
|
'myField' => [ |
34
|
|
|
'type' => Type::boolean(), |
35
|
|
|
'resolve' => function () { |
36
|
|
|
return false; |
37
|
|
|
}, |
38
|
|
|
], |
39
|
|
|
], |
40
|
|
|
]); |
41
|
|
|
$this->executor->addSchema('global', new Schema(['query' => $queryType])); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @expectedException \RuntimeException |
46
|
|
|
* @expectedExceptionMessage Execution result should be an object instantiating "GraphQL\Executor\ExecutionResult". |
47
|
|
|
*/ |
48
|
|
|
public function testInvalidExecutorReturnNotObject() |
49
|
|
|
{ |
50
|
|
|
$this->executor->setExecutor($this->createExecutorExecuteMock(false)); |
|
|
|
|
51
|
|
|
$this->executor->execute(null, $this->request); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @expectedException \RuntimeException |
56
|
|
|
* @expectedExceptionMessage Execution result should be an object instantiating "GraphQL\Executor\ExecutionResult". |
57
|
|
|
*/ |
58
|
|
|
public function testInvalidExecutorReturnInvalidObject() |
59
|
|
|
{ |
60
|
|
|
$this->executor->setExecutor($this->createExecutorExecuteMock(new \stdClass())); |
|
|
|
|
61
|
|
|
$this->executor->execute(null, $this->request); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @expectedException \RuntimeException |
66
|
|
|
* @expectedExceptionMessage PromiseAdapter should be an object instantiating "Overblog\GraphQLBundle\Executor\Promise\PromiseAdapterInterface" or "GraphQL\Executor\Promise\PromiseAdapter" with a "wait" method. |
67
|
|
|
*/ |
68
|
|
|
public function testInvalidExecutorAdapterPromise() |
69
|
|
|
{ |
70
|
|
|
$this->executor->setPromiseAdapter(new ReactPromiseAdapter()); |
71
|
|
|
$this->executor->execute(null, $this->request); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @expectedException \RuntimeException |
76
|
|
|
* @expectedExceptionMessage At least one schema should be declare. |
77
|
|
|
*/ |
78
|
|
|
public function testGetSchemaNoSchemaFound() |
79
|
|
|
{ |
80
|
|
|
(new RequestExecutor(new Executor(), $this->dispatcher))->getSchema('fake'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function createExecutorExecuteMock($returnValue) |
84
|
|
|
{ |
85
|
|
|
$mock = $this->getMockBuilder(Executor::class) |
86
|
|
|
->setMethods(['execute']) |
87
|
|
|
->getMock(); |
88
|
|
|
|
89
|
|
|
$mock->method('execute')->will($this->returnValue($returnValue)); |
90
|
|
|
|
91
|
|
|
return $mock; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: