From a3923b4df79804b43b72104b973cbdd2f099e902 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Tue, 9 Jun 2020 14:01:18 +0200 Subject: [PATCH] Clean up test suite --- composer.json | 3 +++ phpunit.xml.dist | 4 ++-- tests/ConnectionManagerDelayTest.php | 3 ++- tests/ConnectionManagerRejectTest.php | 8 +++++--- tests/ConnectionManagerRepeatTest.php | 2 ++ tests/ConnectionManagerSwappableTest.php | 2 ++ tests/ConnectionManagerTimeoutTest.php | 4 +++- .../Multiple/ConnectionManagerConcurrentTest.php | 3 +++ .../Multiple/ConnectionManagerConsecutiveTest.php | 3 +++ tests/Multiple/ConnectionManagerRandomTest.php | 3 +++ tests/Multiple/ConnectionManagerSelectiveTest.php | 3 +++ tests/{bootstrap.php => TestCase.php} | 15 ++++----------- 12 files changed, 35 insertions(+), 18 deletions(-) rename tests/{bootstrap.php => TestCase.php} (90%) diff --git a/composer.json b/composer.json index 725cf85..365cd04 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,9 @@ "autoload": { "psr-4": { "ConnectionManager\\Extra\\": "src" } }, + "autoload-dev": { + "psr-4": { "ConnectionManager\\Tests\\Extra\\": "tests/" } + }, "require": { "php": ">=5.3", "react/socket": "^1.0 || ^0.8 || ^0.7", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2c09010..ad03596 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,8 @@ - + - + ./tests diff --git a/tests/ConnectionManagerDelayTest.php b/tests/ConnectionManagerDelayTest.php index e959ca1..9b4e8d8 100644 --- a/tests/ConnectionManagerDelayTest.php +++ b/tests/ConnectionManagerDelayTest.php @@ -1,5 +1,6 @@ loop = React\EventLoop\Factory::create(); + $this->loop = \React\EventLoop\Factory::create(); } public function testDelayTenth() diff --git a/tests/ConnectionManagerRejectTest.php b/tests/ConnectionManagerRejectTest.php index a13466e..8549398 100644 --- a/tests/ConnectionManagerRejectTest.php +++ b/tests/ConnectionManagerRejectTest.php @@ -1,5 +1,7 @@ connect('www.google.com:80'); $text = null; - $promise->then($this->expectCallableNever(), function (Exception $e) use (&$text) { + $promise->then($this->expectCallableNever(), function (\Exception $e) use (&$text) { $text = $e->getMessage(); }); @@ -30,7 +32,7 @@ public function testRejectWithCustomMessage() public function testRejectThrowsCustomException() { $cm = new ConnectionManagerReject(function ($uri) { - throw new RuntimeException('Blocked ' . $uri); + throw new \RuntimeException('Blocked ' . $uri); }); $promise = $cm->connect('www.google.com:80'); @@ -47,7 +49,7 @@ public function testRejectThrowsCustomException() public function testRejectReturnsCustomException() { $cm = new ConnectionManagerReject(function ($uri) { - return new RuntimeException('Blocked ' . $uri); + return new \RuntimeException('Blocked ' . $uri); }); $promise = $cm->connect('www.google.com:80'); diff --git a/tests/ConnectionManagerRepeatTest.php b/tests/ConnectionManagerRepeatTest.php index 5388725..a5aabdb 100644 --- a/tests/ConnectionManagerRepeatTest.php +++ b/tests/ConnectionManagerRepeatTest.php @@ -1,5 +1,7 @@ loop = React\EventLoop\Factory::create(); + $this->loop = \React\EventLoop\Factory::create(); } public function testTimeoutOkay() diff --git a/tests/Multiple/ConnectionManagerConcurrentTest.php b/tests/Multiple/ConnectionManagerConcurrentTest.php index 42b3a0d..1ff2799 100644 --- a/tests/Multiple/ConnectionManagerConcurrentTest.php +++ b/tests/Multiple/ConnectionManagerConcurrentTest.php @@ -1,7 +1,10 @@ getMockBuilder('CallableStub')->getMock(); + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); } protected function createConnectionManagerMock($ret) @@ -86,10 +86,3 @@ protected function assertPromiseReject($promise) $promise->then($this->expectCallableNever(), $this->expectCallableOnce()); } } - -class CallableStub -{ - public function __invoke() - { - } -}