Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: php

php:
- 5.3
- 5.4
Expand All @@ -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
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
11 changes: 6 additions & 5 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use React\Datagram\Socket;
use Clue\React\Block;

class FactoryTest extends TestCase
{
Expand All @@ -16,7 +17,7 @@ public function testCreateClient()
{
$promise = $this->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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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());
Expand Down
19 changes: 10 additions & 9 deletions tests/SocketTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use React\Datagram\Socket;
use Clue\React\Block;

class SocketTest extends TestCase
{
Expand All @@ -15,7 +16,7 @@ public function setUp()
public function testCreateClientCloseWillNotBlock()
{
$promise = $this->factory->createClient('127.0.0.1:12345');
$client = $this->getValueFromResolvedPromise($promise);
$client = Block\await($promise, $this->loop);

$client->send('test');
$client->close();
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 0 additions & 19 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down