From 18ad0cee591f4bc0780a56b4d23d20a6b932aa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 21 Dec 2017 14:22:38 +0100 Subject: [PATCH] Forward compatibility with PHPUnit 5 and PHPUnit 6 --- composer.json | 2 +- tests/BufferTest.php | 7 ++++++- tests/TestCase.php | 6 ++++-- tests/UnwrapReadableTest.php | 6 +++--- tests/UnwrapWritableTest.php | 14 +++++++------- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 53ebcff..d2aec73 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,6 @@ "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", "react/promise-timer": "^1.0", "clue/block-react": "^1.0", - "phpunit/phpunit": "^4.8" + "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" } } diff --git a/tests/BufferTest.php b/tests/BufferTest.php index 970ee99..567d26a 100644 --- a/tests/BufferTest.php +++ b/tests/BufferTest.php @@ -93,7 +93,12 @@ public function testMaximumSize() $promise = Stream\buffer($stream, 16); - $this->setExpectedException('\OverflowException', 'Buffer exceeded maximum length'); + if (method_exists($this, 'expectException')) { + $this->expectException('OverflowException'); + $this->expectExceptionMessage('Buffer exceeded maximum length'); + } else { + $this->setExpectedException('\OverflowException', 'Buffer exceeded maximum length'); + } Block\await($promise, $loop, 10); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 842b94b..f73c2d4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,9 @@ namespace React\Tests\Promise\Stream; -class TestCase extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase as BaseTestCase; + +class TestCase extends BaseTestCase { protected function expectCallableOnce() { @@ -51,7 +53,7 @@ protected function expectCallableNever() */ protected function createCallableMock() { - return $this->getMock('React\Tests\Promise\Stream\CallableStub'); + return $this->getMockBuilder('React\Tests\Promise\Stream\CallableStub')->getMock(); } protected function expectPromiseResolve($promise) diff --git a/tests/UnwrapReadableTest.php b/tests/UnwrapReadableTest.php index 75eb0ac..1297131 100644 --- a/tests/UnwrapReadableTest.php +++ b/tests/UnwrapReadableTest.php @@ -191,7 +191,7 @@ public function testEmitsCloseOnlyOnceWhenClosingStreamMultipleTimes() public function testForwardsPauseToInputStream() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $input->expects($this->once())->method('pause'); $promise = Promise\resolve($input); @@ -202,7 +202,7 @@ public function testForwardsPauseToInputStream() public function testForwardsResumeToInputStream() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $input->expects($this->once())->method('resume'); $promise = Promise\resolve($input); @@ -231,7 +231,7 @@ public function testPipingStreamWillForwardDataEvents() public function testClosingStreamWillCloseInputStream() { - $input = $this->getMock('React\Stream\ReadableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock(); $input->expects($this->once())->method('isReadable')->willReturn(true); $input->expects($this->once())->method('close'); diff --git a/tests/UnwrapWritableTest.php b/tests/UnwrapWritableTest.php index 8a6d384..d70d85f 100644 --- a/tests/UnwrapWritableTest.php +++ b/tests/UnwrapWritableTest.php @@ -138,7 +138,7 @@ public function testReturnsStreamThatWillBeClosedWhenPromiseResolvesWithClosedIn public function testForwardsDataImmediatelyIfPromiseIsAlreadyResolved() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->once())->method('write')->with('hello'); $input->expects($this->never())->method('end'); @@ -151,7 +151,7 @@ public function testForwardsDataImmediatelyIfPromiseIsAlreadyResolved() public function testForwardsDataInOneGoOncePromiseResolves() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->once())->method('write')->with('helloworld'); $input->expects($this->never())->method('end'); @@ -169,7 +169,7 @@ public function testForwardsDataInOneGoOncePromiseResolves() public function testForwardsDataAndEndImmediatelyIfPromiseIsAlreadyResolved() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->once())->method('write')->with('hello'); $input->expects($this->once())->method('end')->with('!'); @@ -183,7 +183,7 @@ public function testForwardsDataAndEndImmediatelyIfPromiseIsAlreadyResolved() public function testForwardsDataAndEndOncePromiseResolves() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->once())->method('write')->with('helloworld!'); $input->expects($this->once())->method('end'); @@ -202,7 +202,7 @@ public function testForwardsDataAndEndOncePromiseResolves() public function testForwardsNoDataWhenWritingAfterEndIfPromiseIsAlreadyResolved() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->never())->method('write'); $input->expects($this->once())->method('end'); @@ -217,7 +217,7 @@ public function testForwardsNoDataWhenWritingAfterEndIfPromiseIsAlreadyResolved( public function testForwardsNoDataWhenWritingAfterEndOncePromiseResolves() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->never())->method('write'); $input->expects($this->once())->method('end'); @@ -272,7 +272,7 @@ public function testEmitsCloseOnlyOnceWhenClosingStreamMultipleTimes() public function testClosingStreamWillCloseInputStream() { - $input = $this->getMock('React\Stream\WritableStreamInterface'); + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); $input->expects($this->once())->method('isWritable')->willReturn(true); $input->expects($this->once())->method('close');