Skip to content

Commit

Permalink
Merge pull request #133 from gabriel-caruso/phpunit
Browse files Browse the repository at this point in the history
Forward compatibility with PHPUnit 6
  • Loading branch information
jsor committed Nov 18, 2017
2 parents a73caf8 + 4896aac commit ae97217
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"require-dev": {
"clue/block-react": "^1.2",
"phpunit/phpunit": "^5.0 || ^4.8"
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 3 additions & 4 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
$this->assertNotRegExp('#^HTTP/1\.0#', $response);
}

/** @test */
public function testConnectingFailsIfDnsUsesInvalidResolver()
{
$loop = Factory::create();
Expand All @@ -114,7 +113,6 @@ public function testConnectingFailsIfDnsUsesInvalidResolver()
Block\await($connector->connect('google.com:80'), $loop, self::TIMEOUT);
}

/** @test */
public function testConnectingFailsIfTimeoutIsTooSmall()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -131,7 +129,6 @@ public function testConnectingFailsIfTimeoutIsTooSmall()
Block\await($connector->connect('google.com:80'), $loop, self::TIMEOUT);
}

/** @test */
public function testSelfSignedRejectsIfVerificationIsEnabled()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -150,7 +147,6 @@ public function testSelfSignedRejectsIfVerificationIsEnabled()
Block\await($connector->connect('tls://self-signed.badssl.com:443'), $loop, self::TIMEOUT);
}

/** @test */
public function testSelfSignedResolvesIfVerificationIsDisabled()
{
if (!function_exists('stream_socket_enable_crypto')) {
Expand All @@ -167,6 +163,9 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()

$conn = Block\await($connector->connect('tls://self-signed.badssl.com:443'), $loop, self::TIMEOUT);
$conn->close();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testCancelPendingConnection()
Expand Down
3 changes: 3 additions & 0 deletions tests/SecureIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function testConnectToServer()
/* @var $client ConnectionInterface */

$client->close();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testConnectToServerEmitsConnection()
Expand Down
6 changes: 4 additions & 2 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class ServerTest extends TestCase
{
const TIMEOUT = 0.1;

public function testCreateServer()
public function testCreateServerWithZeroPortAssignsRandomPort()
{
$loop = Factory::create();

$server = new Server(0, $loop);
$this->assertNotEquals(0, $server->getAddress());
$server->close();
}

/**
Expand Down Expand Up @@ -80,7 +82,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer()

$server = new Server(0, $loop);
$server->pause();

$server->on('connection', $this->expectCallableNever());

$client = stream_socket_client($server->getAddress());

Expand Down
14 changes: 0 additions & 14 deletions tests/TcpConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,6 @@ public function connectionToInvalidSchemeShouldFailImmediately()
);
}

/** @test */
public function connectionWithInvalidContextShouldFailImmediately()
{
$this->markTestIncomplete();

$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();

$connector = new TcpConnector($loop, array('bindto' => 'invalid.invalid:123456'));
$connector->connect('127.0.0.1:80')->then(
$this->expectCallableNever(),
$this->expectCallableOnce()
);
}

/** @test */
public function cancellingConnectionShouldRejectPromise()
{
Expand Down
9 changes: 9 additions & 0 deletions tests/TcpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,18 @@ public function testLoopWillEndWhenServerIsClosed()
$this->server = null;

$this->loop->run();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testCloseTwiceIsNoOp()
{
$this->server->close();
$this->server->close();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testGetAddressAfterCloseReturnsNull()
Expand All @@ -136,6 +142,9 @@ public function testLoopWillEndWhenServerIsClosedAfterSingleConnection()
});

$this->loop->run();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts()
Expand Down
20 changes: 19 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use React\EventLoop\LoopInterface;
use Clue\React\Block;
use React\Promise\Promise;
use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends BaseTestCase
{
protected function expectCallableExactly($amount)
{
Expand Down Expand Up @@ -80,4 +81,21 @@ function () use ($stream) {
}
), $loop, $timeout);
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}
13 changes: 9 additions & 4 deletions tests/UnixServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,18 @@ public function testLoopWillEndWhenServerIsClosed()
$this->server = null;

$this->loop->run();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testCloseTwiceIsNoOp()
{
$this->server->close();
$this->server->close();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testGetAddressAfterCloseReturnsNull()
Expand All @@ -129,6 +135,9 @@ public function testLoopWillEndWhenServerIsClosedAfterSingleConnection()
});

$this->loop->run();

// if we reach this, then everything is good
$this->assertNull(null);
}

public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts()
Expand Down Expand Up @@ -164,9 +173,6 @@ public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmo
$this->assertEquals($bytes, $received);
}

/**
* @covers React\EventLoop\StreamSelectLoop::tick
*/
public function testConnectionDoesNotEndWhenClientDoesNotClose()
{
$client = stream_socket_client($this->uds);
Expand All @@ -181,7 +187,6 @@ public function testConnectionDoesNotEndWhenClientDoesNotClose()
}

/**
* @covers React\EventLoop\StreamSelectLoop::tick
* @covers React\Socket\Connection::end
*/
public function testConnectionDoesEndWhenClientCloses()
Expand Down

0 comments on commit ae97217

Please sign in to comment.