Skip to content
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

Update PHPUnit configuration schema for PHPUnit 9.3 and minor clean up and remove already covered test #156

Merged
merged 2 commits into from
Nov 25, 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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ jobs:
- os: osx

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
- time php examples/91-benchmark-throughput.php
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"clue/stream-filter": "~1.2"
},
"autoload": {
Expand Down
16 changes: 10 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +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="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</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="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 2 additions & 12 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@

class TestCase extends BaseTestCase
{
protected function expectCallableExactly($amount)
{
$mock = $this->createCallableMock();
$mock
->expects($this->exactly($amount))
->method('__invoke');

return $mock;
}

protected function expectCallableOnce()
{
$mock = $this->createCallableMock();
Expand Down Expand Up @@ -61,7 +51,7 @@ protected function createCallableMock()
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5+
// PHPUnit 5.2+
$this->expectException($exception);
if ($exceptionMessage !== '') {
$this->expectExceptionMessage($exceptionMessage);
Expand All @@ -70,7 +60,7 @@ public function setExpectedException($exception, $exceptionMessage = '', $except
$this->expectExceptionCode($exceptionCode);
}
} else {
// legacy PHPUnit 4
// legacy PHPUnit 4 - PHPUnit 5.1
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}
Expand Down
5 changes: 0 additions & 5 deletions tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,4 @@ private function createLoopMock()
{
return $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
}

private function notEqualTo($value)
{
return new \PHPUnit_Framework_Constraint_Not($value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,33 +461,6 @@ public function testWritingToClosedWritableResourceStreamShouldNotWriteToStream(
$this->assertSame('', $filterBuffer);
}

/**
* @covers React\Stream\WritableResourceStream::handleWrite
*/
public function testErrorWhenStreamResourceIsInvalid()
{
$stream = fopen('php://temp', 'r+');
$loop = $this->createWriteableLoopMock();

$error = null;

$buffer = new WritableResourceStream($stream, $loop);
$buffer->on('error', function ($message) use (&$error) {
$error = $message;
});

// invalidate stream resource
fclose($stream);

$buffer->write('Attempting to write to bad stream');

$this->assertInstanceOf('Exception', $error);

// the error messages differ between PHP versions, let's just check substrings
$this->assertContainsString('Unable to write to stream: ', $error->getMessage());
$this->assertContainsStringIgnoringCase(' Not a valid stream resource', $error->getMessage());
}

public function testWritingToClosedStream()
{
if ('Darwin' === PHP_OS) {
Expand Down