|
5 | 5 | use Clue\React\Block; |
6 | 6 | use PHPUnit\Framework\MockObject\MockObject; |
7 | 7 | use Psr\Http\Message\RequestInterface; |
8 | | -use RingCentral\Psr7\Response; |
| 8 | +use Psr\Http\Message\ResponseInterface; |
| 9 | +use React\Http\Io\ReadableBodyStream; |
9 | 10 | use React\Http\Io\Transaction; |
10 | 11 | use React\Http\Message\ResponseException; |
11 | 12 | use React\EventLoop\Loop; |
|
14 | 15 | use React\Stream\ThroughStream; |
15 | 16 | use React\Tests\Http\TestCase; |
16 | 17 | use RingCentral\Psr7\Request; |
17 | | -use React\Http\Io\ReadableBodyStream; |
| 18 | +use RingCentral\Psr7\Response; |
18 | 19 |
|
19 | 20 | class TransactionTest extends TestCase |
20 | 21 | { |
@@ -372,13 +373,14 @@ public function testReceivingErrorResponseWillRejectWithResponseException() |
372 | 373 | $transaction = $transaction->withOptions(array('timeout' => -1)); |
373 | 374 | $promise = $transaction->send($request); |
374 | 375 |
|
375 | | - try { |
376 | | - Block\await($promise, $loop); |
377 | | - $this->fail(); |
378 | | - } catch (ResponseException $exception) { |
379 | | - $this->assertEquals(404, $exception->getCode()); |
380 | | - $this->assertSame($response, $exception->getResponse()); |
381 | | - } |
| 376 | + $exception = null; |
| 377 | + $promise->then(null, function ($reason) use (&$exception) { |
| 378 | + $exception = $reason; |
| 379 | + }); |
| 380 | + |
| 381 | + assert($exception instanceof ResponseException); |
| 382 | + $this->assertEquals(404, $exception->getCode()); |
| 383 | + $this->assertSame($response, $exception->getResponse()); |
382 | 384 | } |
383 | 385 |
|
384 | 386 | public function testReceivingStreamingBodyWillResolveWithBufferedResponseByDefault() |
@@ -461,8 +463,12 @@ public function testReceivingStreamingBodyWillResolveWithStreamingResponseIfStre |
461 | 463 | $transaction = $transaction->withOptions(array('streaming' => true, 'timeout' => -1)); |
462 | 464 | $promise = $transaction->send($request); |
463 | 465 |
|
464 | | - $response = Block\await($promise, $loop); |
| 466 | + $response = null; |
| 467 | + $promise->then(function ($value) use (&$response) { |
| 468 | + $response = $value; |
| 469 | + }); |
465 | 470 |
|
| 471 | + assert($response instanceof ResponseInterface); |
466 | 472 | $this->assertEquals(200, $response->getStatusCode()); |
467 | 473 | $this->assertEquals('', (string)$response->getBody()); |
468 | 474 | } |
|
0 commit comments