Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid referencing unneeded explicit loop instance
  • Loading branch information
clue committed Aug 9, 2022
commit 90413fb088d701f77f12e50e5f471e3f000aca2a
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ $browser = new React\Http\Browser();
$promise = $browser->get('http://example.com/');

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

$responses = Block\awaitAll($promises, Loop::get());
$responses = Block\awaitAll($promises);
```

Please refer to [clue/reactphp-block](https://github.com/clue/reactphp-block#readme) for more details.
Expand Down
32 changes: 24 additions & 8 deletions tests/Io/SenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ public function testSenderRejectsInvalidUri()

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

$this->setExpectedException('InvalidArgumentException');
Block\await($promise, $this->loop);
$exception = null;
$promise->then(null, function ($e) use (&$exception) {
$exception = $e;
});

$this->assertInstanceOf('InvalidArgumentException', $exception);
}

public function testSenderConnectorRejection()
Expand All @@ -57,8 +61,12 @@ public function testSenderConnectorRejection()

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

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
$exception = null;
$promise->then(null, function ($e) use (&$exception) {
$exception = $e;
});

$this->assertInstanceOf('RuntimeException', $exception);
}

public function testSendPostWillAutomaticallySendContentLengthHeader()
Expand Down Expand Up @@ -318,8 +326,12 @@ public function testCancelRequestWillCancelConnector()
$promise = $sender->send($request);
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
$exception = null;
$promise->then(null, function ($e) use (&$exception) {
$exception = $e;
});

$this->assertInstanceOf('RuntimeException', $exception);
}

public function testCancelRequestWillCloseConnection()
Expand All @@ -337,8 +349,12 @@ public function testCancelRequestWillCloseConnection()
$promise = $sender->send($request);
$promise->cancel();

$this->setExpectedException('RuntimeException');
Block\await($promise, $this->loop);
$exception = null;
$promise->then(null, function ($e) use (&$exception) {
$exception = $e;
});

$this->assertInstanceOf('RuntimeException', $exception);
}

public function provideRequestProtocolVersion()
Expand Down
26 changes: 16 additions & 10 deletions tests/Io/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Clue\React\Block;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\RequestInterface;
use RingCentral\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use React\Http\Io\ReadableBodyStream;
use React\Http\Io\Transaction;
use React\Http\Message\ResponseException;
use React\EventLoop\Loop;
Expand All @@ -14,7 +15,7 @@
use React\Stream\ThroughStream;
use React\Tests\Http\TestCase;
use RingCentral\Psr7\Request;
use React\Http\Io\ReadableBodyStream;
use RingCentral\Psr7\Response;

class TransactionTest extends TestCase
{
Expand Down Expand Up @@ -372,13 +373,14 @@ public function testReceivingErrorResponseWillRejectWithResponseException()
$transaction = $transaction->withOptions(array('timeout' => -1));
$promise = $transaction->send($request);

try {
Block\await($promise, $loop);
$this->fail();
} catch (ResponseException $exception) {
$this->assertEquals(404, $exception->getCode());
$this->assertSame($response, $exception->getResponse());
}
$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
$exception = $reason;
});

assert($exception instanceof ResponseException);
$this->assertEquals(404, $exception->getCode());
$this->assertSame($response, $exception->getResponse());
}

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

$response = Block\await($promise, $loop);
$response = null;
$promise->then(function ($value) use (&$response) {
$response = $value;
});

assert($response instanceof ResponseInterface);
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('', (string)$response->getBody());
}
Expand Down