diff --git a/.travis.yml b/.travis.yml index e4b60c0..fae3474 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: php # lock distro so new future defaults will not break the build dist: trusty -matrix: +jobs: include: - php: 5.3 dist: precise @@ -17,7 +17,7 @@ matrix: - php: 7.4 install: - - composer install --no-interaction + - composer install script: - vendor/bin/phpunit --coverage-text diff --git a/composer.json b/composer.json index 5fada8a..f8b6647 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,6 @@ "clue/block-react": "^1.0 || ^0.3", "clue/caret-notation": "^0.2", "clue/tar-react": "^0.2", - "phpunit/phpunit": "^7.0 || ^6.0 || ^5.0 || ^4.8.35" + "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35" } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 8afadf3..a1d1ed2 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -17,7 +17,10 @@ class ClientTest extends TestCase private $streamingParser; private $client; - public function setUp() + /** + * @before + */ + public function setUpClient() { $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); $this->browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock(); @@ -48,11 +51,9 @@ public function testCtor() new Client($this->loop); } - /** - * @expectedException InvalidArgumentException - */ public function testCtorWithInvalidUrlThrows() { + $this->setExpectedException('InvalidArgumentException'); new Client($this->loop, 'ftp://invalid'); } diff --git a/tests/FunctionalClientTest.php b/tests/FunctionalClientTest.php index f0b46f4..0a21ef8 100644 --- a/tests/FunctionalClientTest.php +++ b/tests/FunctionalClientTest.php @@ -11,7 +11,10 @@ class FunctionalClientTest extends TestCase { private $client; - public function setUp() + /** + * @before + */ + public function setUpClient() { $this->loop = LoopFactory::create(); $this->client = new Client($this->loop); @@ -349,12 +352,10 @@ public function testRemoveRunning($container) $this->assertEquals('', $ret); } - /** - * @expectedException RuntimeException - */ public function testContainerRemoveInvalid() { $promise = $this->client->containerRemove('invalid123'); + $this->setExpectedException('RuntimeException'); Block\await($promise, $this->loop); } diff --git a/tests/Io/ReadableDemultiplexStreamTest.php b/tests/Io/ReadableDemultiplexStreamTest.php index 14453fc..a005237 100644 --- a/tests/Io/ReadableDemultiplexStreamTest.php +++ b/tests/Io/ReadableDemultiplexStreamTest.php @@ -11,7 +11,10 @@ class ReadableDemultiplexStreamTest extends TestCase private $stream; private $parser; - public function setUp() + /** + * @before + */ + public function setUpParser() { $this->stream = new ThroughStream(); $this->parser = new ReadableDemultiplexStream($this->stream); diff --git a/tests/Io/ReadableJsonStreamTest.php b/tests/Io/ReadableJsonStreamTest.php index 72282c0..ad1a7cc 100644 --- a/tests/Io/ReadableJsonStreamTest.php +++ b/tests/Io/ReadableJsonStreamTest.php @@ -11,7 +11,10 @@ class ReadableJsonStreamTest extends TestCase private $stream; private $parser; - public function setUp() + /** + * @before + */ + public function setUpParser() { $this->stream = new ThroughStream(); $this->parser = new ReadableJsonStream($this->stream); diff --git a/tests/Io/ResponseParserTest.php b/tests/Io/ResponseParserTest.php index 4e01cd2..61e2020 100644 --- a/tests/Io/ResponseParserTest.php +++ b/tests/Io/ResponseParserTest.php @@ -10,7 +10,10 @@ class ResponseParserTest extends TestCase { private $parser; - public function setUp() + /** + * @before + */ + public function setUpParser() { $this->parser = new ResponseParser(); } diff --git a/tests/Io/StreamingParserTest.php b/tests/Io/StreamingParserTest.php index ee7a4a8..7ab1784 100644 --- a/tests/Io/StreamingParserTest.php +++ b/tests/Io/StreamingParserTest.php @@ -13,7 +13,10 @@ class StreamingParserTest extends TestCase { private $parser; - public function setUp() + /** + * @before + */ + public function setUpParser() { $this->parser = new StreamingParser(); } diff --git a/tests/TestCase.php b/tests/TestCase.php index ccf774f..b823773 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -48,7 +48,13 @@ protected function expectCallableOnceParameter($type) protected function createCallableMock() { - return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) { + // PHPUnit 8.5+ + return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock(); + } else { + // legacy PHPUnit 4 - PHPUnit 8.4 + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + } } protected function expectPromiseResolve($promise) @@ -73,4 +79,21 @@ protected function expectPromiseReject($promise) return $promise; } + + public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null) + { + if (method_exists($this, 'expectException')) { + // PHPUnit 5.2+ + $this->expectException($exception); + if ($exceptionMessage !== '') { + $this->expectExceptionMessage($exceptionMessage); + } + if ($exceptionCode !== null) { + $this->expectExceptionCode($exceptionCode); + } + } else { + // legacy PHPUnit 4 - PHPUnit 5.1 + parent::setExpectedException($exception, $exceptionMessage, $exceptionCode); + } + } }