From 5fdc7ef6222d4aab24077284f8369afe4186be57 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sun, 12 Nov 2017 00:10:38 -0200 Subject: [PATCH 1/3] Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase --- composer.json | 2 +- tests/TestCase.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ecce7c34..509b7146 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require-dev": { "clue/block-react": "^1.2", - "phpunit/phpunit": "^5.0 || ^4.8" + "phpunit/phpunit": "^5.7 || ^4.8.35" }, "autoload": { "psr-4": { diff --git a/tests/TestCase.php b/tests/TestCase.php index 81e925d6..91785eea 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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) { From 908f2f591a7c88a5736de7fb989f670e427bab56 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Mon, 13 Nov 2017 02:39:01 -0200 Subject: [PATCH 2/3] Support PHPUnit 6 --- composer.json | 2 +- tests/IntegrationTest.php | 4 ---- tests/TestCase.php | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 509b7146..a3c4cf60 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require-dev": { "clue/block-react": "^1.2", - "phpunit/phpunit": "^5.7 || ^4.8.35" + "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" }, "autoload": { "psr-4": { diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 01232dba..a220453d 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -98,7 +98,6 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork() $this->assertNotRegExp('#^HTTP/1\.0#', $response); } - /** @test */ public function testConnectingFailsIfDnsUsesInvalidResolver() { $loop = Factory::create(); @@ -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')) { @@ -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')) { @@ -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')) { diff --git a/tests/TestCase.php b/tests/TestCase.php index 91785eea..e87fc2f1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -81,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); + } + } } From 4896aacb248b9f8f1b302b2b9d130fd7aa51c6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 18 Nov 2017 17:06:59 +0100 Subject: [PATCH 3/3] Improve risky tests to contain rudimentary assertions --- tests/IntegrationTest.php | 3 +++ tests/SecureIntegrationTest.php | 3 +++ tests/ServerTest.php | 6 ++++-- tests/TcpConnectorTest.php | 14 -------------- tests/TcpServerTest.php | 9 +++++++++ tests/UnixServerTest.php | 13 +++++++++---- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index a220453d..194ed539 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -163,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() diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index 357acb65..8c9ba14d 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -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() diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 1a5d2a90..14fdb2c8 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -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(); } /** @@ -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()); diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index 526fb6ab..17c55240 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -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() { diff --git a/tests/TcpServerTest.php b/tests/TcpServerTest.php index d66ba6f6..72b3c28d 100644 --- a/tests/TcpServerTest.php +++ b/tests/TcpServerTest.php @@ -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() @@ -136,6 +142,9 @@ public function testLoopWillEndWhenServerIsClosedAfterSingleConnection() }); $this->loop->run(); + + // if we reach this, then everything is good + $this->assertNull(null); } public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts() diff --git a/tests/UnixServerTest.php b/tests/UnixServerTest.php index 51f49601..10f7e4f6 100644 --- a/tests/UnixServerTest.php +++ b/tests/UnixServerTest.php @@ -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() @@ -129,6 +135,9 @@ public function testLoopWillEndWhenServerIsClosedAfterSingleConnection() }); $this->loop->run(); + + // if we reach this, then everything is good + $this->assertNull(null); } public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmounts() @@ -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); @@ -181,7 +187,6 @@ public function testConnectionDoesNotEndWhenClientDoesNotClose() } /** - * @covers React\EventLoop\StreamSelectLoop::tick * @covers React\Socket\Connection::end */ public function testConnectionDoesEndWhenClientCloses() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy