Skip to content

Commit 8f44ad8

Browse files
authored
Merge pull request #153 from SimonFrings/tests
Run tests on PHPUnit 9 and clean up test suite
2 parents 7c02b51 + 56eafea commit 8f44ad8

File tree

9 files changed

+68
-38
lines changed

9 files changed

+68
-38
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: php
33
# lock distro so new future defaults will not break the build
44
dist: trusty
55

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
1010
},
1111
"require-dev": {
12-
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35",
12+
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35",
1313
"clue/stream-filter": "~1.2"
1414
},
1515
"autoload": {

phpunit.xml.dist

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
bootstrap="vendor/autoload.php"
12-
>
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
134
<testsuites>
145
<testsuite name="React Test Suite">
156
<directory>./tests/</directory>

tests/CallableStub.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/DuplexResourceStreamTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ public function testConstructorWithExcessiveMode()
3838

3939
/**
4040
* @covers React\Stream\DuplexResourceStream::__construct
41-
* @expectedException InvalidArgumentException
4241
*/
4342
public function testConstructorThrowsExceptionOnInvalidStream()
4443
{
4544
$loop = $this->createLoopMock();
4645

46+
$this->setExpectedException('InvalidArgumentException');
4747
new DuplexResourceStream('breakme', $loop);
4848
}
4949

5050
/**
5151
* @covers React\Stream\DuplexResourceStream::__construct
52-
* @expectedException InvalidArgumentException
5352
*/
5453
public function testConstructorThrowsExceptionOnWriteOnlyStream()
5554
{
@@ -59,12 +58,12 @@ public function testConstructorThrowsExceptionOnWriteOnlyStream()
5958

6059
$loop = $this->createLoopMock();
6160

61+
$this->setExpectedException('InvalidArgumentException');
6262
new DuplexResourceStream(STDOUT, $loop);
6363
}
6464

6565
/**
6666
* @covers React\Stream\DuplexResourceStream::__construct
67-
* @expectedException InvalidArgumentException
6867
*/
6968
public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode()
7069
{
@@ -74,12 +73,12 @@ public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode
7473
unlink($name);
7574

7675
$loop = $this->createLoopMock();
76+
$this->setExpectedException('InvalidArgumentException');
7777
new DuplexResourceStream($stream, $loop);
7878
}
7979

8080
/**
8181
* @covers React\Stream\DuplexResourceStream::__construct
82-
* @expectedException RunTimeException
8382
*/
8483
public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking()
8584
{
@@ -90,6 +89,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking(
9089
$stream = fopen('blocking://test', 'r+');
9190
$loop = $this->createLoopMock();
9291

92+
$this->setExpectedException('RunTimeException');
9393
new DuplexResourceStream($stream, $loop);
9494
}
9595

tests/ReadableResourceStreamTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@ public function testConstructorWithExcessiveMode()
3737

3838
/**
3939
* @covers React\Stream\ReadableResourceStream::__construct
40-
* @expectedException InvalidArgumentException
4140
*/
4241
public function testConstructorThrowsExceptionOnInvalidStream()
4342
{
4443
$loop = $this->createLoopMock();
4544

45+
$this->setExpectedException('InvalidArgumentException');
4646
new ReadableResourceStream(false, $loop);
4747
}
4848

4949
/**
5050
* @covers React\Stream\ReadableResourceStream::__construct
51-
* @expectedException InvalidArgumentException
5251
*/
5352
public function testConstructorThrowsExceptionOnWriteOnlyStream()
5453
{
@@ -58,12 +57,12 @@ public function testConstructorThrowsExceptionOnWriteOnlyStream()
5857

5958
$loop = $this->createLoopMock();
6059

60+
$this->setExpectedException('InvalidArgumentException');
6161
new ReadableResourceStream(STDOUT, $loop);
6262
}
6363

6464
/**
6565
* @covers React\Stream\ReadableResourceStream::__construct
66-
* @expectedException InvalidArgumentException
6766
*/
6867
public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode()
6968
{
@@ -73,12 +72,12 @@ public function testConstructorThrowsExceptionOnWriteOnlyStreamWithExcessiveMode
7372
unlink($name);
7473

7574
$loop = $this->createLoopMock();
75+
$this->setExpectedException('InvalidArgumentException');
7676
new ReadableResourceStream($stream, $loop);
7777
}
7878

7979
/**
8080
* @covers React\Stream\ReadableResourceStream::__construct
81-
* @expectedException RuntimeException
8281
*/
8382
public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking()
8483
{
@@ -89,6 +88,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking(
8988
$stream = fopen('blocking://test', 'r+');
9089
$loop = $this->createLoopMock();
9190

91+
$this->setExpectedException('RuntimeException');
9292
new ReadableResourceStream($stream, $loop);
9393
}
9494

tests/TestCase.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,51 @@ protected function expectCallableNever()
4949

5050
protected function createCallableMock()
5151
{
52-
return $this->getMockBuilder('React\Tests\Stream\CallableStub')->getMock();
52+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
53+
// PHPUnit 9+
54+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
55+
} else {
56+
// legacy PHPUnit 4 - PHPUnit 9
57+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
58+
}
59+
}
60+
61+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
62+
{
63+
if (method_exists($this, 'expectException')) {
64+
// PHPUnit 5+
65+
$this->expectException($exception);
66+
if ($exceptionMessage !== '') {
67+
$this->expectExceptionMessage($exceptionMessage);
68+
}
69+
if ($exceptionCode !== null) {
70+
$this->expectExceptionCode($exceptionCode);
71+
}
72+
} else {
73+
// legacy PHPUnit 4
74+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
75+
}
76+
}
77+
78+
public function assertContainsString($needle, $haystack)
79+
{
80+
if (method_exists($this, 'assertStringContainsString')) {
81+
// PHPUnit 7.5+
82+
$this->assertStringContainsString($needle, $haystack);
83+
} else {
84+
// legacy PHPUnit 4 - PHPUnit 7.5
85+
$this->assertContains($needle, $haystack);
86+
}
87+
}
88+
89+
public function assertContainsStringIgnoringCase($needle, $haystack)
90+
{
91+
if (method_exists($this, 'assertStringContainsStringIgnoringCase')) {
92+
// PHPUnit 7.5+
93+
$this->assertStringContainsStringIgnoringCase($needle, $haystack);
94+
} else {
95+
// legacy PHPUnit 4 - PHPUnit 7.5
96+
$this->assertContains($needle, $haystack, '', true);
97+
}
5398
}
5499
}

tests/ThroughStreamTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class ThroughStreamTest extends TestCase
1111
{
1212
/**
1313
* @test
14-
* @expectedException InvalidArgumentException
1514
*/
1615
public function itShouldRejectInvalidCallback()
1716
{
17+
$this->setExpectedException('InvalidArgumentException');
1818
new ThroughStream(123);
1919
}
2020

tests/WritableStreamResourceTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,30 @@ public function testConstructorWithExcessiveMode()
3737

3838
/**
3939
* @covers React\Stream\WritableResourceStream::__construct
40-
* @expectedException InvalidArgumentException
4140
*/
4241
public function testConstructorThrowsIfNotAValidStreamResource()
4342
{
4443
$stream = null;
4544
$loop = $this->createLoopMock();
4645

46+
$this->setExpectedException('InvalidArgumentException');
4747
new WritableResourceStream($stream, $loop);
4848
}
4949

5050
/**
5151
* @covers React\Stream\WritableResourceStream::__construct
52-
* @expectedException InvalidArgumentException
5352
*/
5453
public function testConstructorThrowsExceptionOnReadOnlyStream()
5554
{
5655
$stream = fopen('php://temp', 'r');
5756
$loop = $this->createLoopMock();
5857

58+
$this->setExpectedException('InvalidArgumentException');
5959
new WritableResourceStream($stream, $loop);
6060
}
6161

6262
/**
6363
* @covers React\Stream\WritableResourceStream::__construct
64-
* @expectedException InvalidArgumentException
6564
*/
6665
public function testConstructorThrowsExceptionOnReadOnlyStreamWithExcessiveMode()
6766
{
@@ -71,12 +70,12 @@ public function testConstructorThrowsExceptionOnReadOnlyStreamWithExcessiveMode(
7170
unlink($name);
7271

7372
$loop = $this->createLoopMock();
73+
$this->setExpectedException('InvalidArgumentException');
7474
new WritableResourceStream($stream, $loop);
7575
}
7676

7777
/**
7878
* @covers React\Stream\WritableResourceStream::__construct
79-
* @expectedException RuntimeException
8079
*/
8180
public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking()
8281
{
@@ -87,6 +86,7 @@ public function testConstructorThrowsExceptionIfStreamDoesNotSupportNonBlocking(
8786
$stream = fopen('blocking://test', 'r+');
8887
$loop = $this->createLoopMock();
8988

89+
$this->setExpectedException('RuntimeException');
9090
new WritableResourceStream($stream, $loop);
9191
}
9292

@@ -325,6 +325,10 @@ public function testEndWithoutDataDoesNotCloseIfWritableResourceStreamIsFull()
325325
*/
326326
public function testEndWithDataClosesImmediatelyIfWritableResourceStreamFlushes()
327327
{
328+
if (defined('HHVM_VERSION')) {
329+
$this->markTestSkipped('Not supported on HHVM');
330+
}
331+
328332
$stream = fopen('php://temp', 'r+');
329333
$filterBuffer = '';
330334
$loop = $this->createLoopMock();
@@ -480,8 +484,8 @@ public function testErrorWhenStreamResourceIsInvalid()
480484
$this->assertInstanceOf('Exception', $error);
481485

482486
// the error messages differ between PHP versions, let's just check substrings
483-
$this->assertContains('Unable to write to stream: ', $error->getMessage());
484-
$this->assertContains(' not a valid stream resource', $error->getMessage(), '', true);
487+
$this->assertContainsString('Unable to write to stream: ', $error->getMessage());
488+
$this->assertContainsStringIgnoringCase(' Not a valid stream resource', $error->getMessage());
485489
}
486490

487491
public function testWritingToClosedStream()

0 commit comments

Comments
 (0)