From 97a84e0a7bd41f16eb0be6311d741cb3cf84b686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 12 Dec 2017 17:57:04 +0100 Subject: [PATCH] Forward compatibility with PHPUnit 6 --- composer.json | 2 +- tests/ClientTest.php | 10 ++++++++++ tests/FunctionalTest.php | 22 ++++++++++++++++------ tests/ServerTest.php | 6 ++++++ tests/bootstrap.php | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index b5d3498..6762a08 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "evenement/evenement": "~3.0|~1.0|~2.0" }, "require-dev": { - "phpunit/phpunit": "^5.0 || ^4.8", + "phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", "clue/connection-manager-extra": "^1.0 || ^0.7", "clue/block-react": "^1.1" diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 0d179ef..450f186 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -23,16 +23,22 @@ public function setUp() public function testCtorAcceptsUriWithHostAndPort() { $client = new Client('127.0.0.1:9050', $this->connector); + + $this->assertTrue(true); } public function testCtorAcceptsUriWithScheme() { $client = new Client('socks://127.0.0.1:9050', $this->connector); + + $this->assertTrue(true); } public function testCtorAcceptsUriWithHostOnlyAssumesDefaultPort() { $client = new Client('127.0.0.1', $this->connector); + + $this->assertTrue(true); } /** @@ -46,6 +52,8 @@ public function testCtorThrowsForInvalidUri() public function testValidAuthFromUri() { $this->client = new Client('username:password@127.0.0.1', $this->connector); + + $this->assertTrue(true); } /** @@ -59,6 +67,8 @@ public function testInvalidAuthInformation() public function testValidAuthAndVersionFromUri() { $this->client = new Client('socks5://username:password@127.0.0.1:9050', $this->connector); + + $this->assertTrue(true); } /** diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 5e318c8..01de80e 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -181,7 +181,7 @@ public function testConnectionInvalidProtocolDoesNotMatchSocks5() $this->server->setProtocolVersion(5); $this->client = new Client('socks4a://127.0.0.1:' . $this->port, $this->connector); - $this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_ECONNRESET); + $this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_ECONNRESET); } public function testConnectionInvalidProtocolDoesNotMatchSocks4() @@ -189,7 +189,7 @@ public function testConnectionInvalidProtocolDoesNotMatchSocks4() $this->server->setProtocolVersion(4); $this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector); - $this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_ECONNRESET); + $this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_ECONNRESET); } public function testConnectionInvalidNoAuthentication() @@ -198,7 +198,7 @@ public function testConnectionInvalidNoAuthentication() $this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector); - $this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_EACCES); + $this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES); } public function testConnectionInvalidAuthenticationMismatch() @@ -207,7 +207,7 @@ public function testConnectionInvalidAuthenticationMismatch() $this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector); - $this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_EACCES); + $this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES); } /** @group internet */ @@ -310,11 +310,21 @@ private function assertResolveStream($promise) Block\await($promise, $this->loop, 2.0); } - private function assertRejectPromise($promise, $message = '', $code = null) + private function assertRejectPromise($promise, $message = null, $code = null) { $this->expectPromiseReject($promise); - $this->setExpectedException('Exception', $message, $code); + if (method_exists($this, 'expectException')) { + $this->expectException('Exception'); + if ($message !== null) { + $this->expectExceptionMessage($message); + } + if ($code !== null) { + $this->expectExceptionCode($code); + } + } else { + $this->setExpectedException('Exception', $message, $code); + } Block\await($promise, $this->loop, 2.0); } diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 1fed263..f378c74 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -30,6 +30,8 @@ public function testSetProtocolVersion() $this->server->setProtocolVersion('4a'); $this->server->setProtocolVersion(5); $this->server->setProtocolVersion(null); + + $this->assertTrue(true); } /** @@ -48,6 +50,8 @@ public function testSetAuthArray() 'name1' => 'password1', 'name2' => 'password2' )); + + $this->assertTrue(true); } /** @@ -390,5 +394,7 @@ public function testUnsetAuth() { $this->server->unsetAuth(); $this->server->unsetAuth(); + + $this->assertTrue(true); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3dbb0ca..029c6b9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ (include_once __DIR__.'/../vendor/autoload.php') OR die(PHP_EOL.'ERROR: composer autoloader not found, run "composer install" or see README for instructions'.PHP_EOL); -class TestCase extends PHPUnit_Framework_TestCase +class TestCase extends PHPUnit\Framework\TestCase { protected function expectCallableOnce() {