1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Error; |
4
|
|
|
|
5
|
|
|
use GraphQL\Executor\Promise\Promise; |
6
|
|
|
use Overblog\GraphQLBundle\Executor\Promise\Adapter\ReactPromiseAdapter; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use React\Promise\FulfilledPromise; |
9
|
|
|
use Symfony\Component\Process\PhpProcess; |
10
|
|
|
|
11
|
|
|
class ReactPromiseAdapterTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** @var ReactPromiseAdapter */ |
14
|
|
|
private $adapter; |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->adapter = new ReactPromiseAdapter(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @expectedException \InvalidArgumentException |
23
|
|
|
* @expectedExceptionMessage The "Overblog\GraphQLBundle\Executor\Promise\Adapter\ReactPromiseAdapter::wait" method must be call with compatible a Promise. |
24
|
|
|
*/ |
25
|
|
|
public function testWaitWithNotSupportedPromise() |
26
|
|
|
{ |
27
|
|
|
$noSupportedPromise = new Promise(new \stdClass(), $this->adapter); |
28
|
|
|
$this->adapter->wait($noSupportedPromise); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @expectedException \Exception |
33
|
|
|
* @expectedExceptionMessage Promise has been rejected! |
34
|
|
|
*/ |
35
|
|
|
public function testWaitRejectedPromise() |
36
|
|
|
{ |
37
|
|
|
$rejected = $this->adapter->createRejected(new \Exception('Promise has been rejected!')); |
|
|
|
|
38
|
|
|
$this->adapter->wait($rejected); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testWaitAsyncPromise() |
42
|
|
|
{ |
43
|
|
|
$output = 'OK!'; |
44
|
|
|
$process = new PhpProcess(<<<EOF |
45
|
|
|
<?php |
46
|
|
|
usleep(30); |
47
|
|
|
echo '$output'; |
48
|
|
|
EOF |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$promise = $this->adapter->create(function (callable $resolve) use (&$process) { |
52
|
|
|
$process->start(function () use ($resolve, &$process) { |
53
|
|
|
$output = $process->getOutput(); |
54
|
|
|
$resolve($output); |
55
|
|
|
}); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
$this->assertEquals( |
59
|
|
|
$output, |
60
|
|
|
$this->adapter->wait($promise, function () use (&$process) { |
61
|
|
|
$process->wait(); |
62
|
|
|
}) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testSkipsConversionWhenPromiseIsAGraphQlOne() |
67
|
|
|
{ |
68
|
|
|
$reactAdapter = new ReactPromiseAdapter(); |
69
|
|
|
$reactPromise = new FulfilledPromise(1); |
70
|
|
|
|
71
|
|
|
$promise = $reactAdapter->convertThenable($reactPromise); |
72
|
|
|
// Test it's already converted then skip it |
73
|
|
|
$reactAdapter->convertThenable($promise); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf(Promise::class, $promise); |
76
|
|
|
$this->assertInstanceOf(FulfilledPromise::class, $promise->adoptedPromise); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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: