|
1 | 1 | <?php
|
2 | 2 | namespace Http\Curl\Tests;
|
3 | 3 |
|
4 |
| -use Http\Client\Promise; |
| 4 | +use Http\Client\Exception\TransferException; |
| 5 | +use Http\Promise\Promise; |
5 | 6 | use Http\Curl\CurlPromise;
|
6 | 7 | use Http\Curl\MultiRunner;
|
7 | 8 |
|
@@ -34,14 +35,38 @@ public function testCoreCalls()
|
34 | 35 |
|
35 | 36 | $core->expects(static::once())->method('getState')->willReturn('STATE');
|
36 | 37 | static::assertEquals('STATE', $promise->getState());
|
| 38 | + } |
37 | 39 |
|
| 40 | + public function testCoreCallWaitFulfilled() |
| 41 | + { |
| 42 | + $core = $this->createPromiseCore(); |
| 43 | + $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor() |
| 44 | + ->setMethods(['wait'])->getMock(); |
| 45 | + /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ |
| 46 | + $promise = new CurlPromise($core, $runner); |
| 47 | + |
| 48 | + $runner->expects(static::once())->method('wait')->with($core); |
| 49 | + $core->expects(static::once())->method('getState')->willReturn(Promise::FULFILLED); |
38 | 50 | $core->expects(static::once())->method('getResponse')->willReturn('RESPONSE');
|
39 |
| - static::assertEquals('RESPONSE', $promise->getResponse()); |
| 51 | + static::assertEquals('RESPONSE', $promise->wait()); |
| 52 | + } |
40 | 53 |
|
41 |
| - $core->expects(static::once())->method('getException')->willReturn('EXCEPTION'); |
42 |
| - static::assertEquals('EXCEPTION', $promise->getException()); |
| 54 | + public function testCoreCallWaitRejected() |
| 55 | + { |
| 56 | + $core = $this->createPromiseCore(); |
| 57 | + $runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor() |
| 58 | + ->setMethods(['wait'])->getMock(); |
| 59 | + /** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */ |
| 60 | + $promise = new CurlPromise($core, $runner); |
43 | 61 |
|
44 | 62 | $runner->expects(static::once())->method('wait')->with($core);
|
45 |
| - $promise->wait(); |
| 63 | + $core->expects(static::once())->method('getState')->willReturn(Promise::REJECTED); |
| 64 | + $core->expects(static::once())->method('getException')->willReturn(new TransferException()); |
| 65 | + |
| 66 | + try { |
| 67 | + $promise->wait(); |
| 68 | + } catch (TransferException $exception) { |
| 69 | + static::assertTrue(true); |
| 70 | + } |
46 | 71 | }
|
47 | 72 | }
|
0 commit comments