Skip to content

Commit 306886e

Browse files
authored
Merge pull request #94 from SimonFrings/tests
Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3
2 parents bcc67f3 + 49f8eff commit 306886e

9 files changed

+106
-34
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/.travis.yml export-ignore
44
/examples/ export-ignore
55
/phpunit.xml.dist export-ignore
6+
/phpunit.xml.legacy export-ignore
67
/tests/ export-ignore

.travis.yml

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

6-
matrix:
6+
jobs:
77
include:
88
- php: 5.3
99
dist: precise
@@ -19,10 +19,9 @@ matrix:
1919
allow_failures:
2020
- php: hhvm-3.18
2121

22-
sudo: false
23-
2422
install:
25-
- composer install --no-interaction
23+
- composer install
2624

2725
script:
28-
- vendor/bin/phpunit --coverage-text
26+
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
27+
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"require-dev": {
3030
"clue/arguments": "^2.0",
3131
"clue/commander": "^1.2",
32-
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
32+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
3333
},
3434
"config": {
3535
"sort-packages": true

phpunit.xml.dist

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

3-
<phpunit bootstrap="vendor/autoload.php" colors="true">
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
cacheResult="false">
49
<testsuites>
510
<testsuite name="Stdio React Test Suite">
611
<directory>./tests/</directory>
712
</testsuite>
813
</testsuites>
9-
<filter>
10-
<whitelist>
14+
<coverage>
15+
<include>
1116
<directory>./src/</directory>
12-
</whitelist>
13-
</filter>
14-
</phpunit>
17+
</include>
18+
</coverage>
19+
</phpunit>

phpunit.xml.legacy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="Stdio React Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/FunctionalExampleTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ public function testPeriodicExampleWithPipedInputEndsBecauseInputEnds()
88
{
99
$output = $this->execExample('echo hello | php 01-periodic.php');
1010

11-
$this->assertContains('you just said: hello\n', $output);
11+
$this->assertContainsString('you just said: hello\n', $output);
1212
}
1313

1414
public function testPeriodicExampleWithNullInputQuitsImmediately()
1515
{
1616
$output = $this->execExample('php 01-periodic.php < /dev/null');
1717

18-
$this->assertNotContains('you just said:', $output);
18+
$this->assertNotContainsString('you just said:', $output);
1919
}
2020

2121
public function testPeriodicExampleWithNoInputQuitsImmediately()
2222
{
2323
$output = $this->execExample('true | php 01-periodic.php');
2424

25-
$this->assertNotContains('you just said:', $output);
25+
$this->assertNotContainsString('you just said:', $output);
2626
}
2727

2828
public function testPeriodicExampleWithSleepNoInputQuitsOnEnd()
2929
{
3030
$output = $this->execExample('sleep 0.1 | php 01-periodic.php');
3131

32-
$this->assertNotContains('you just said:', $output);
32+
$this->assertNotContainsString('you just said:', $output);
3333
}
3434

3535
public function testPeriodicExampleWithClosedInputQuitsImmediately()
@@ -40,7 +40,7 @@ public function testPeriodicExampleWithClosedInputQuitsImmediately()
4040
$this->markTestIncomplete('Your platform exhibits a closed STDIN bug, this may need some further debugging');
4141
}
4242

43-
$this->assertNotContains('you just said:', $output);
43+
$this->assertNotContainsString('you just said:', $output);
4444
}
4545

4646
public function testPeriodicExampleWithClosedInputAndOutputQuitsImmediatelyWithoutOutput()
@@ -58,28 +58,28 @@ public function testBindingsExampleWithPipedInputEndsBecauseInputEnds()
5858
{
5959
$output = $this->execExample('echo test | php 04-bindings.php');
6060

61-
$this->assertContains('you just said: test (4)' . PHP_EOL, $output);
61+
$this->assertContainsString('you just said: test (4)' . PHP_EOL, $output);
6262
}
6363

6464
public function testBindingsExampleWithPipedInputEndsWithSpecialBindingsReplacedBecauseInputEnds()
6565
{
6666
$output = $this->execExample('echo hello | php 04-bindings.php');
6767

68-
$this->assertContains('you just said: hellö (6)' . PHP_EOL, $output);
68+
$this->assertContainsString('you just said: hellö (6)' . PHP_EOL, $output);
6969
}
7070

7171
public function testStubShowStdinIsReadableByDefault()
7272
{
7373
$output = $this->execExample('php ../tests/stub/01-check-stdin.php');
7474

75-
$this->assertContains('YES', $output);
75+
$this->assertContainsString('YES', $output);
7676
}
7777

7878
public function testStubCanCloseStdinAndIsNotReadable()
7979
{
8080
$output = $this->execExample('php ../tests/stub/02-close-stdin.php');
8181

82-
$this->assertContains('NO', $output);
82+
$this->assertContainsString('NO', $output);
8383
}
8484

8585
public function testStubCanCloseStdoutAndIsNotWritable()
@@ -113,7 +113,7 @@ public function testPeriodicExampleViaInteractiveModeQuitsImmediately()
113113

114114
// starts with either "Interactive mode enabled" or "Interactive shell"
115115
$this->assertStringStartsWith('Interactive ', $output);
116-
$this->assertNotContains('you just said:', $output);
116+
$this->assertNotContainsString('you just said:', $output);
117117
}
118118

119119
private function execExample($command)

tests/ReadlineTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class ReadlineTest extends TestCase
1212
private $output;
1313
private $readline;
1414

15-
public function setUp()
15+
/**
16+
* @before
17+
*/
18+
public function setUpReadline()
1619
{
1720
$this->input = new ThroughStream();
1821
$this->output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
@@ -621,11 +624,9 @@ public function testAutocompleteReturnsSelf()
621624
$this->assertSame($this->readline, $this->readline->setAutocomplete(function () { }));
622625
}
623626

624-
/**
625-
* @expectedException InvalidArgumentException
626-
*/
627627
public function testAutocompleteThrowsIfNotCallable()
628628
{
629+
$this->setExpectedException('InvalidArgumentException');
629630
$this->assertSame($this->readline, $this->readline->setAutocomplete(123));
630631
}
631632

@@ -931,7 +932,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatch()
931932

932933
$this->readline->onKeyTab();
933934

934-
$this->assertContains("\na b\n", $buffer);
935+
$this->assertContainsString("\na b\n", $buffer);
935936
}
936937

937938
public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchWithEmptyWord()
@@ -945,7 +946,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchWithEmptyW
945946

946947
$this->readline->onKeyTab();
947948

948-
$this->assertContains("\n a\n", $buffer);
949+
$this->assertContainsString("\n a\n", $buffer);
949950
}
950951

951952
public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncompleteWord()
@@ -961,7 +962,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncomplete
961962

962963
$this->readline->onKeyTab();
963964

964-
$this->assertContains("\nhello hellu\n", $buffer);
965+
$this->assertContainsString("\nhello hellu\n", $buffer);
965966
}
966967

967968
public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncompleteWordWithUmlauts()
@@ -977,7 +978,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncomplete
977978

978979
$this->readline->onKeyTab();
979980

980-
$this->assertContains("\nhällö hällü\n", $buffer);
981+
$this->assertContainsString("\nhällö hällü\n", $buffer);
981982
}
982983

983984
public function testAutocompleteShowsAvailableOptionsWithoutDuplicatesWhenMultipleMatch()
@@ -991,7 +992,7 @@ public function testAutocompleteShowsAvailableOptionsWithoutDuplicatesWhenMultip
991992

992993
$this->readline->onKeyTab();
993994

994-
$this->assertContains("\na b\n", $buffer);
995+
$this->assertContainsString("\na b\n", $buffer);
995996
}
996997

997998
public function testAutocompleteShowsLimitedNumberOfAvailableOptionsWhenMultipleMatch()
@@ -1005,7 +1006,7 @@ public function testAutocompleteShowsLimitedNumberOfAvailableOptionsWhenMultiple
10051006

10061007
$this->readline->onKeyTab();
10071008

1008-
$this->assertContains("\na b c d e f g (+19 others)\n", $buffer);
1009+
$this->assertContainsString("\na b c d e f g (+19 others)\n", $buffer);
10091010
}
10101011

10111012
public function testBindCustomFunctionFromBase()

tests/StdioTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class StdioTest extends TestCase
1111
{
1212
private $loop;
1313

14-
public function setUp()
14+
/**
15+
* @before
16+
*/
17+
public function setUpLoop()
1518
{
1619
$this->loop = Factory::create();
1720
}

tests/TestCase.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ protected function expectCallableOnceWith($value)
4646
*/
4747
protected function createCallableMock()
4848
{
49-
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
49+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
50+
// PHPUnit 9+
51+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
52+
} else {
53+
// legacy PHPUnit 4 - PHPUnit 8
54+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
55+
}
5056
}
5157

5258
protected function expectPromiseResolve($promise)
@@ -66,4 +72,43 @@ protected function expectPromiseReject($promise)
6672

6773
return $promise;
6874
}
75+
76+
public function assertContainsString($needle, $haystack)
77+
{
78+
if (method_exists($this, 'assertStringContainsString')) {
79+
// PHPUnit 7.5+
80+
$this->assertStringContainsString($needle, $haystack);
81+
} else {
82+
// legacy PHPUnit 4 - PHPUnit 7.5
83+
$this->assertContains($needle, $haystack);
84+
}
85+
}
86+
87+
public function assertNotContainsString($needle, $haystack)
88+
{
89+
if (method_exists($this, 'assertStringNotContainsString')) {
90+
// PHPUnit 7.5+
91+
$this->assertStringNotContainsString($needle, $haystack);
92+
} else {
93+
// legacy PHPUnit 4 - PHPUnit 7.5
94+
$this->assertNotContains($needle, $haystack);
95+
}
96+
}
97+
98+
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
99+
{
100+
if (method_exists($this, 'expectException')) {
101+
// PHPUnit 5+
102+
$this->expectException($exception);
103+
if ($exceptionMessage !== '') {
104+
$this->expectExceptionMessage($exceptionMessage);
105+
}
106+
if ($exceptionCode !== null) {
107+
$this->expectExceptionCode($exceptionCode);
108+
}
109+
} else {
110+
// legacy PHPUnit 4
111+
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
112+
}
113+
}
69114
}

0 commit comments

Comments
 (0)