Skip to content

Commit 90413fb

Browse files
committed
Avoid referencing unneeded explicit loop instance
1 parent b3ff9c8 commit 90413fb

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ $browser = new React\Http\Browser();
386386
$promise = $browser->get('http://example.com/');
387387

388388
try {
389-
$response = Block\await($promise, Loop::get());
389+
$response = Block\await($promise);
390390
// response successfully received
391391
} catch (Exception $e) {
392392
// an error occurred while performing the request
@@ -401,7 +401,7 @@ $promises = array(
401401
$browser->get('http://www.example.org/'),
402402
);
403403

404-
$responses = Block\awaitAll($promises, Loop::get());
404+
$responses = Block\awaitAll($promises);
405405
```
406406

407407
Please refer to [clue/reactphp-block](https://github.com/clue/reactphp-block#readme) for more details.

tests/Io/SenderTest.php

+24-8
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ public function testSenderRejectsInvalidUri()
4242

4343
$promise = $sender->send($request);
4444

45-
$this->setExpectedException('InvalidArgumentException');
46-
Block\await($promise, $this->loop);
45+
$exception = null;
46+
$promise->then(null, function ($e) use (&$exception) {
47+
$exception = $e;
48+
});
49+
50+
$this->assertInstanceOf('InvalidArgumentException', $exception);
4751
}
4852

4953
public function testSenderConnectorRejection()
@@ -57,8 +61,12 @@ public function testSenderConnectorRejection()
5761

5862
$promise = $sender->send($request);
5963

60-
$this->setExpectedException('RuntimeException');
61-
Block\await($promise, $this->loop);
64+
$exception = null;
65+
$promise->then(null, function ($e) use (&$exception) {
66+
$exception = $e;
67+
});
68+
69+
$this->assertInstanceOf('RuntimeException', $exception);
6270
}
6371

6472
public function testSendPostWillAutomaticallySendContentLengthHeader()
@@ -318,8 +326,12 @@ public function testCancelRequestWillCancelConnector()
318326
$promise = $sender->send($request);
319327
$promise->cancel();
320328

321-
$this->setExpectedException('RuntimeException');
322-
Block\await($promise, $this->loop);
329+
$exception = null;
330+
$promise->then(null, function ($e) use (&$exception) {
331+
$exception = $e;
332+
});
333+
334+
$this->assertInstanceOf('RuntimeException', $exception);
323335
}
324336

325337
public function testCancelRequestWillCloseConnection()
@@ -337,8 +349,12 @@ public function testCancelRequestWillCloseConnection()
337349
$promise = $sender->send($request);
338350
$promise->cancel();
339351

340-
$this->setExpectedException('RuntimeException');
341-
Block\await($promise, $this->loop);
352+
$exception = null;
353+
$promise->then(null, function ($e) use (&$exception) {
354+
$exception = $e;
355+
});
356+
357+
$this->assertInstanceOf('RuntimeException', $exception);
342358
}
343359

344360
public function provideRequestProtocolVersion()

tests/Io/TransactionTest.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Clue\React\Block;
66
use PHPUnit\Framework\MockObject\MockObject;
77
use Psr\Http\Message\RequestInterface;
8-
use RingCentral\Psr7\Response;
8+
use Psr\Http\Message\ResponseInterface;
9+
use React\Http\Io\ReadableBodyStream;
910
use React\Http\Io\Transaction;
1011
use React\Http\Message\ResponseException;
1112
use React\EventLoop\Loop;
@@ -14,7 +15,7 @@
1415
use React\Stream\ThroughStream;
1516
use React\Tests\Http\TestCase;
1617
use RingCentral\Psr7\Request;
17-
use React\Http\Io\ReadableBodyStream;
18+
use RingCentral\Psr7\Response;
1819

1920
class TransactionTest extends TestCase
2021
{
@@ -372,13 +373,14 @@ public function testReceivingErrorResponseWillRejectWithResponseException()
372373
$transaction = $transaction->withOptions(array('timeout' => -1));
373374
$promise = $transaction->send($request);
374375

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());
382384
}
383385

384386
public function testReceivingStreamingBodyWillResolveWithBufferedResponseByDefault()
@@ -461,8 +463,12 @@ public function testReceivingStreamingBodyWillResolveWithStreamingResponseIfStre
461463
$transaction = $transaction->withOptions(array('streaming' => true, 'timeout' => -1));
462464
$promise = $transaction->send($request);
463465

464-
$response = Block\await($promise, $loop);
466+
$response = null;
467+
$promise->then(function ($value) use (&$response) {
468+
$response = $value;
469+
});
465470

471+
assert($response instanceof ResponseInterface);
466472
$this->assertEquals(200, $response->getStatusCode());
467473
$this->assertEquals('', (string)$response->getBody());
468474
}

0 commit comments

Comments
 (0)