diff --git a/.travis.yml b/.travis.yml index 9f1f9ff..57ab098 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: php + php: - 5.3 - 5.4 @@ -7,7 +8,10 @@ php: - 7 - hhvm -before_script: - - composer install --dev --prefer-source --no-interaction +sudo: false + +install: + - composer install --prefer-source --no-interaction + script: - phpunit --coverage-text diff --git a/composer.json b/composer.json index 49c1588..e78f6ab 100644 --- a/composer.json +++ b/composer.json @@ -19,5 +19,8 @@ "react/event-loop": ">=0.2, <0.5", "react/dns": ">=0.2, <0.5", "react/promise": "~2.0|~1.1" + }, + "require-dev": { + "clue/block-react": "~1.0" } } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index e2f499a..65adfe2 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -1,6 +1,7 @@ factory->createClient('127.0.0.1:12345'); - $capturedClient = $this->getValueFromResolvedPromise($promise); + $capturedClient = Block\await($promise, $this->loop); $this->assertInstanceOf('React\Datagram\Socket', $capturedClient); $capturedClient->close(); @@ -26,7 +27,7 @@ public function testCreateClientLocalhost() { $promise = $this->factory->createClient('localhost:12345'); - $capturedClient = $this->getValueFromResolvedPromise($promise); + $capturedClient = Block\await($promise, $this->loop); $this->assertInstanceOf('React\Datagram\Socket', $capturedClient); $capturedClient->close(); @@ -36,7 +37,7 @@ public function testCreateClientIpv6() { $promise = $this->factory->createClient('[::1]:12345'); - $capturedClient = $this->getValueFromResolvedPromise($promise); + $capturedClient = Block\await($promise, $this->loop); $this->assertInstanceOf('React\Datagram\Socket', $capturedClient); $capturedClient->close(); @@ -46,7 +47,7 @@ public function testCreateServer() { $promise = $this->factory->createServer('127.0.0.1:12345'); - $capturedServer = $this->getValueFromResolvedPromise($promise); + $capturedServer = Block\await($promise, $this->loop); $this->assertInstanceOf('React\Datagram\Socket', $capturedServer); $capturedServer->close(); @@ -56,7 +57,7 @@ public function testCreateServerRandomPort() { $promise = $this->factory->createServer('127.0.0.1:0'); - $capturedServer = $this->getValueFromResolvedPromise($promise); + $capturedServer = Block\await($promise, $this->loop); $this->assertInstanceOf('React\Datagram\Socket', $capturedServer); $this->assertNotEquals('127.0.0.1:0', $capturedServer->getLocalAddress()); diff --git a/tests/SocketTest.php b/tests/SocketTest.php index b5e9416..c885033 100644 --- a/tests/SocketTest.php +++ b/tests/SocketTest.php @@ -1,6 +1,7 @@ factory->createClient('127.0.0.1:12345'); - $client = $this->getValueFromResolvedPromise($promise); + $client = Block\await($promise, $this->loop); $client->send('test'); $client->close(); @@ -39,7 +40,7 @@ public function testClientCloseAgainWillNotBlock(Socket $client) public function testCreateClientEndWillNotBlock() { $promise = $this->factory->createClient('127.0.0.1:12345'); - $client = $this->getValueFromResolvedPromise($promise); + $client = Block\await($promise, $this->loop); $client->send('test'); $client->end(); @@ -76,7 +77,7 @@ public function testClientSendAfterEndIsNoop(Socket $client) public function testClientSendHugeWillFail() { $promise = $this->factory->createClient('127.0.0.1:12345'); - $client = $this->getValueFromResolvedPromise($promise); + $client = Block\await($promise, $this->loop); $client->send(str_repeat(1, 1024 * 1024)); $client->on('error', $this->expectCallableOnce()); @@ -88,7 +89,7 @@ public function testClientSendHugeWillFail() public function testClientSendNoServerWillFail() { $promise = $this->factory->createClient('127.0.0.1:1234'); - $client = $this->getValueFromResolvedPromise($promise); + $client = Block\await($promise, $this->loop); // send a message to a socket that is not actually listening // expect the remote end to reject this by sending an ICMP message @@ -114,10 +115,10 @@ public function testClientSendNoServerWillFail() public function testCreatePair() { $promise = $this->factory->createServer('127.0.0.1:0'); - $server = $this->getValueFromResolvedPromise($promise); + $server = Block\await($promise, $this->loop); $promise = $this->factory->createClient($server->getLocalAddress()); - $client = $this->getValueFromResolvedPromise($promise); + $client = Block\await($promise, $this->loop); $that = $this; $server->on('message', function ($message, $remote, $server) use ($that) { @@ -158,10 +159,10 @@ public function provideSanitizeAddress() public function testSanitizeAddress($address) { $promise = $this->factory->createServer($address); - $server = $this->getValueFromResolvedPromise($promise); - + $server = Block\await($promise, $this->loop); + $promise = $this->factory->createClient($server->getLocalAddress()); - $client = $this->getValueFromResolvedPromise($promise); + $client = Block\await($promise, $this->loop); $that = $this; $server->on('message', function ($message, $remote, $server) use ($that) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e1004a2..a94af33 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,25 +4,6 @@ abstract class TestCase extends PHPUnit_Framework_TestCase { - protected function getValueFromResolvedPromise($promise) - { - $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); - - $loop = $this->loop; - $capturedValue = null; - $promise->then(function ($value) use (&$capturedValue, $loop) { - $capturedValue = $value; - $loop->stop(); - }, $this->expectCallableNever()); - - // future-turn resolutions are not enforced, so the value MAY be known here already - if ($capturedValue === null) { - $loop->run(); - } - - return $capturedValue; - } - protected function expectCallableOnce() { $mock = $this->createCallableMock();