Skip to content

Commit 3c9018d

Browse files
authored
Merge pull request #12 from clue-labs/phpunit
Forward compatibility with PHPUnit 5 and PHPUnit 6
2 parents 4e3dbdd + 18ad0ce commit 3c9018d

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
2727
"react/promise-timer": "^1.0",
2828
"clue/block-react": "^1.0",
29-
"phpunit/phpunit": "^4.8"
29+
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
3030
}
3131
}

tests/BufferTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ public function testMaximumSize()
9393

9494
$promise = Stream\buffer($stream, 16);
9595

96-
$this->setExpectedException('\OverflowException', 'Buffer exceeded maximum length');
96+
if (method_exists($this, 'expectException')) {
97+
$this->expectException('OverflowException');
98+
$this->expectExceptionMessage('Buffer exceeded maximum length');
99+
} else {
100+
$this->setExpectedException('\OverflowException', 'Buffer exceeded maximum length');
101+
}
97102
Block\await($promise, $loop, 10);
98103
}
99104

tests/TestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace React\Tests\Promise\Stream;
44

5-
class TestCase extends \PHPUnit_Framework_TestCase
5+
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
7+
class TestCase extends BaseTestCase
68
{
79
protected function expectCallableOnce()
810
{
@@ -51,7 +53,7 @@ protected function expectCallableNever()
5153
*/
5254
protected function createCallableMock()
5355
{
54-
return $this->getMock('React\Tests\Promise\Stream\CallableStub');
56+
return $this->getMockBuilder('React\Tests\Promise\Stream\CallableStub')->getMock();
5557
}
5658

5759
protected function expectPromiseResolve($promise)

tests/UnwrapReadableTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function testEmitsCloseOnlyOnceWhenClosingStreamMultipleTimes()
191191

192192
public function testForwardsPauseToInputStream()
193193
{
194-
$input = $this->getMock('React\Stream\ReadableStreamInterface');
194+
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
195195
$input->expects($this->once())->method('pause');
196196

197197
$promise = Promise\resolve($input);
@@ -202,7 +202,7 @@ public function testForwardsPauseToInputStream()
202202

203203
public function testForwardsResumeToInputStream()
204204
{
205-
$input = $this->getMock('React\Stream\ReadableStreamInterface');
205+
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
206206
$input->expects($this->once())->method('resume');
207207

208208
$promise = Promise\resolve($input);
@@ -231,7 +231,7 @@ public function testPipingStreamWillForwardDataEvents()
231231

232232
public function testClosingStreamWillCloseInputStream()
233233
{
234-
$input = $this->getMock('React\Stream\ReadableStreamInterface');
234+
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
235235
$input->expects($this->once())->method('isReadable')->willReturn(true);
236236
$input->expects($this->once())->method('close');
237237

tests/UnwrapWritableTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testReturnsStreamThatWillBeClosedWhenPromiseResolvesWithClosedIn
138138

139139
public function testForwardsDataImmediatelyIfPromiseIsAlreadyResolved()
140140
{
141-
$input = $this->getMock('React\Stream\WritableStreamInterface');
141+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
142142
$input->expects($this->once())->method('isWritable')->willReturn(true);
143143
$input->expects($this->once())->method('write')->with('hello');
144144
$input->expects($this->never())->method('end');
@@ -151,7 +151,7 @@ public function testForwardsDataImmediatelyIfPromiseIsAlreadyResolved()
151151

152152
public function testForwardsDataInOneGoOncePromiseResolves()
153153
{
154-
$input = $this->getMock('React\Stream\WritableStreamInterface');
154+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
155155
$input->expects($this->once())->method('isWritable')->willReturn(true);
156156
$input->expects($this->once())->method('write')->with('helloworld');
157157
$input->expects($this->never())->method('end');
@@ -169,7 +169,7 @@ public function testForwardsDataInOneGoOncePromiseResolves()
169169

170170
public function testForwardsDataAndEndImmediatelyIfPromiseIsAlreadyResolved()
171171
{
172-
$input = $this->getMock('React\Stream\WritableStreamInterface');
172+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
173173
$input->expects($this->once())->method('isWritable')->willReturn(true);
174174
$input->expects($this->once())->method('write')->with('hello');
175175
$input->expects($this->once())->method('end')->with('!');
@@ -183,7 +183,7 @@ public function testForwardsDataAndEndImmediatelyIfPromiseIsAlreadyResolved()
183183

184184
public function testForwardsDataAndEndOncePromiseResolves()
185185
{
186-
$input = $this->getMock('React\Stream\WritableStreamInterface');
186+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
187187
$input->expects($this->once())->method('isWritable')->willReturn(true);
188188
$input->expects($this->once())->method('write')->with('helloworld!');
189189
$input->expects($this->once())->method('end');
@@ -202,7 +202,7 @@ public function testForwardsDataAndEndOncePromiseResolves()
202202

203203
public function testForwardsNoDataWhenWritingAfterEndIfPromiseIsAlreadyResolved()
204204
{
205-
$input = $this->getMock('React\Stream\WritableStreamInterface');
205+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
206206
$input->expects($this->once())->method('isWritable')->willReturn(true);
207207
$input->expects($this->never())->method('write');
208208
$input->expects($this->once())->method('end');
@@ -217,7 +217,7 @@ public function testForwardsNoDataWhenWritingAfterEndIfPromiseIsAlreadyResolved(
217217

218218
public function testForwardsNoDataWhenWritingAfterEndOncePromiseResolves()
219219
{
220-
$input = $this->getMock('React\Stream\WritableStreamInterface');
220+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
221221
$input->expects($this->once())->method('isWritable')->willReturn(true);
222222
$input->expects($this->never())->method('write');
223223
$input->expects($this->once())->method('end');
@@ -272,7 +272,7 @@ public function testEmitsCloseOnlyOnceWhenClosingStreamMultipleTimes()
272272

273273
public function testClosingStreamWillCloseInputStream()
274274
{
275-
$input = $this->getMock('React\Stream\WritableStreamInterface');
275+
$input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
276276
$input->expects($this->once())->method('isWritable')->willReturn(true);
277277
$input->expects($this->once())->method('close');
278278

0 commit comments

Comments
 (0)