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\Error; |
13
|
|
|
|
14
|
|
|
use GraphQL\Executor\Promise\Promise; |
15
|
|
|
use Overblog\GraphQLBundle\Executor\Promise\Adapter\ReactPromiseAdapter; |
16
|
|
|
use Symfony\Component\Process\PhpProcess; |
17
|
|
|
|
18
|
|
|
class ReactPromiseAdapterTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** @var ReactPromiseAdapter */ |
21
|
|
|
private $adapter; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->adapter = new ReactPromiseAdapter(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @expectedException \InvalidArgumentException |
30
|
|
|
* @expectedExceptionMessage The "Overblog\GraphQLBundle\Executor\Promise\Adapter\ReactPromiseAdapter::wait" method must be call with compatible a Promise. |
31
|
|
|
*/ |
32
|
|
|
public function testWaitWithNotSupportedPromise() |
33
|
|
|
{ |
34
|
|
|
$noSupportedPromise = new Promise(new \stdClass(), $this->adapter); |
35
|
|
|
$this->adapter->wait($noSupportedPromise); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @expectedException \Exception |
40
|
|
|
* @expectedExceptionMessage Promise has been rejected! |
41
|
|
|
*/ |
42
|
|
|
public function testWaitRejectedPromise() |
43
|
|
|
{ |
44
|
|
|
$rejected = $this->adapter->createRejected(new \Exception('Promise has been rejected!')); |
45
|
|
|
$this->adapter->wait($rejected); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testWaitAsyncPromise() |
49
|
|
|
{ |
50
|
|
|
$output = 'OK!'; |
51
|
|
|
$process = new PhpProcess(<<<EOF |
52
|
|
|
<?php |
53
|
|
|
usleep(30); |
54
|
|
|
echo '$output'; |
55
|
|
|
EOF |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$promise = $this->adapter->create(function (callable $resolve) use (&$process) { |
59
|
|
|
$process->start(function () use ($resolve, &$process) { |
60
|
|
|
$output = $process->getOutput(); |
61
|
|
|
$resolve($output); |
62
|
|
|
}); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
$this->assertEquals( |
66
|
|
|
$output, |
67
|
|
|
$this->adapter->wait($promise, function () use (&$process) { |
68
|
|
|
$process->wait(); |
69
|
|
|
}) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|