Skip to content

Run tests on PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3 #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -19,10 +19,9 @@ matrix:
allow_failures:
- php: hhvm-3.18

sudo: false

install:
- composer install --no-interaction
- composer install

script:
- vendor/bin/phpunit --coverage-text
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
- if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"require-dev": {
"clue/arguments": "^2.0",
"clue/commander": "^1.2",
"phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
},
"config": {
"sort-packages": true
Expand Down
17 changes: 11 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResult="false">
<testsuites>
<testsuite name="Stdio React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Stdio React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
20 changes: 10 additions & 10 deletions tests/FunctionalExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ public function testPeriodicExampleWithPipedInputEndsBecauseInputEnds()
{
$output = $this->execExample('echo hello | php 01-periodic.php');

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$this->assertContains('YES', $output);
$this->assertContainsString('YES', $output);
}

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

$this->assertContains('NO', $output);
$this->assertContainsString('NO', $output);
}

public function testStubCanCloseStdoutAndIsNotWritable()
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testPeriodicExampleViaInteractiveModeQuitsImmediately()

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

private function execExample($command)
Expand Down
21 changes: 11 additions & 10 deletions tests/ReadlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class ReadlineTest extends TestCase
private $output;
private $readline;

public function setUp()
/**
* @before
*/
public function setUpReadline()
{
$this->input = new ThroughStream();
$this->output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
Expand Down Expand Up @@ -621,11 +624,9 @@ public function testAutocompleteReturnsSelf()
$this->assertSame($this->readline, $this->readline->setAutocomplete(function () { }));
}

/**
* @expectedException InvalidArgumentException
*/
public function testAutocompleteThrowsIfNotCallable()
{
$this->setExpectedException('InvalidArgumentException');
$this->assertSame($this->readline, $this->readline->setAutocomplete(123));
}

Expand Down Expand Up @@ -931,7 +932,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatch()

$this->readline->onKeyTab();

$this->assertContains("\na b\n", $buffer);
$this->assertContainsString("\na b\n", $buffer);
}

public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchWithEmptyWord()
Expand All @@ -945,7 +946,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchWithEmptyW

$this->readline->onKeyTab();

$this->assertContains("\n a\n", $buffer);
$this->assertContainsString("\n a\n", $buffer);
}

public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncompleteWord()
Expand All @@ -961,7 +962,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncomplete

$this->readline->onKeyTab();

$this->assertContains("\nhello hellu\n", $buffer);
$this->assertContainsString("\nhello hellu\n", $buffer);
}

public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncompleteWordWithUmlauts()
Expand All @@ -977,7 +978,7 @@ public function testAutocompleteShowsAvailableOptionsWhenMultipleMatchIncomplete

$this->readline->onKeyTab();

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

public function testAutocompleteShowsAvailableOptionsWithoutDuplicatesWhenMultipleMatch()
Expand All @@ -991,7 +992,7 @@ public function testAutocompleteShowsAvailableOptionsWithoutDuplicatesWhenMultip

$this->readline->onKeyTab();

$this->assertContains("\na b\n", $buffer);
$this->assertContainsString("\na b\n", $buffer);
}

public function testAutocompleteShowsLimitedNumberOfAvailableOptionsWhenMultipleMatch()
Expand All @@ -1005,7 +1006,7 @@ public function testAutocompleteShowsLimitedNumberOfAvailableOptionsWhenMultiple

$this->readline->onKeyTab();

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

public function testBindCustomFunctionFromBase()
Expand Down
5 changes: 4 additions & 1 deletion tests/StdioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class StdioTest extends TestCase
{
private $loop;

public function setUp()
/**
* @before
*/
public function setUpLoop()
{
$this->loop = Factory::create();
}
Expand Down
47 changes: 46 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ protected function expectCallableOnceWith($value)
*/
protected function createCallableMock()
{
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
// PHPUnit 9+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
} else {
// legacy PHPUnit 4 - PHPUnit 8
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}
}

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

return $promise;
}

public function assertContainsString($needle, $haystack)
{
if (method_exists($this, 'assertStringContainsString')) {
// PHPUnit 7.5+
$this->assertStringContainsString($needle, $haystack);
} else {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertContains($needle, $haystack);
}
}

public function assertNotContainsString($needle, $haystack)
{
if (method_exists($this, 'assertStringNotContainsString')) {
// PHPUnit 7.5+
$this->assertStringNotContainsString($needle, $haystack);
} else {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertNotContains($needle, $haystack);
}
}

public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
}