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

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

Merged
merged 2 commits into from
Aug 20, 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
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: php
# lock distro so new future defaults will not break the build
dist: trusty

matrix:
jobs:
include:
- php: 5.3
dist: precise
Expand All @@ -20,7 +20,8 @@ matrix:
- php: hhvm-3.18

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 @@ -23,6 +23,6 @@
"react/promise-timer": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35"
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"
}
}
15 changes: 10 additions & 5 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="Block 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="Block React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 3 additions & 11 deletions tests/FunctionAwaitAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,36 @@ public function testAwaitAllAllResolved()
$this->assertEquals(array('first' => 1, 'second' => 2), Block\awaitAll($all, $this->loop));
}

/**
* @expectedException Exception
* @expectedExceptionMessage test
*/
public function testAwaitAllRejected()
{
$all = array(
$this->createPromiseResolved(1),
$this->createPromiseRejected(new \Exception('test'))
);

$this->setExpectedException('Exception', 'test');
Block\awaitAll($all, $this->loop);
}

/**
* @expectedException UnexpectedValueException
*/
public function testAwaitAllRejectedWithFalseWillWrapInUnexpectedValueException()
{
$all = array(
$this->createPromiseResolved(1),
Promise\reject(false)
);

$this->setExpectedException('UnexpectedValueException');
Block\awaitAll($all, $this->loop);
}

/**
* @expectedException Exception
* @expectedExceptionMessage first
*/
public function testAwaitAllOnlyRejected()
{
$all = array(
$this->createPromiseRejected(new \Exception('first')),
$this->createPromiseRejected(new \Exception('second'))
);

$this->setExpectedException('Exception', 'first');
Block\awaitAll($all, $this->loop);
}

Expand Down
8 changes: 2 additions & 6 deletions tests/FunctionAwaitAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

class FunctionAwaitAnyTest extends TestCase
{
/**
* @expectedException UnderflowException
*/
public function testAwaitAnyEmpty()
{
$this->setExpectedException('UnderflowException');
Block\awaitAny(array(), $this->loop);
}

Expand Down Expand Up @@ -49,16 +47,14 @@ public function testAwaitAnyFirstResolvedConcurrently()
$this->assertEquals(2, Block\awaitAny($all, $this->loop));
}

/**
* @expectedException UnderflowException
*/
public function testAwaitAnyAllRejected()
{
$all = array(
$this->createPromiseRejected(1),
$this->createPromiseRejected(2)
);

$this->setExpectedException('UnderflowException');
Block\awaitAny($all, $this->loop);
}

Expand Down
19 changes: 4 additions & 15 deletions tests/FunctionAwaitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,27 @@

class FunctionAwaitTest extends TestCase
{
/**
* @expectedException Exception
* @expectedExceptionMessage test
*/
public function testAwaitOneRejected()
{
$promise = $this->createPromiseRejected(new \Exception('test'));

$this->setExpectedException('Exception', 'test');
Block\await($promise, $this->loop);
}

/**
* @expectedException UnexpectedValueException
* @expectedExceptionMessage Promise rejected with unexpected value of type bool
*/
public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException()
{
$promise = Promise\reject(false);

$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type bool');
Block\await($promise, $this->loop);
}

/**
* @expectedException UnexpectedValueException
* @expectedExceptionMessage Promise rejected with unexpected value of type NULL
*/
public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException()
{
$promise = Promise\reject(null);

$this->setExpectedException('UnexpectedValueException', 'Promise rejected with unexpected value of type NULL');
Block\await($promise, $this->loop);
}

Expand Down Expand Up @@ -73,13 +64,11 @@ public function testAwaitOneInterrupted()
$this->assertEquals(2, Block\await($promise, $this->loop));
}

/**
* @expectedException React\Promise\Timer\TimeoutException
*/
public function testAwaitOncePendingWillThrowOnTimeout()
{
$promise = new Promise\Promise(function () { });

$this->setExpectedException('React\Promise\Timer\TimeoutException');
Block\await($promise, $this->loop, 0.001);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionSleepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testSleep()
Block\sleep(0.2, $this->loop);
$time = microtime(true) - $time;

$this->assertEquals(0.2, $time, '', 0.1);
$this->assertEqualsDelta(0.2, $time, 0.1);
}

public function testSleepSmallTimerWillBeCappedReasonably()
Expand All @@ -21,6 +21,6 @@ public function testSleepSmallTimerWillBeCappedReasonably()
Block\sleep(0.0000001, $this->loop);
$time = microtime(true) - $time;

$this->assertEquals(0.1, $time, '', 0.1);
$this->assertEqualsDelta(0.1, $time, 0.1);
}
}
33 changes: 32 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class TestCase extends BaseTestCase
{
protected $loop;

public function setUp()
/**
* @before
*/
public function setUpLoop()
{
$this->loop = \React\EventLoop\Factory::create();
}
Expand Down Expand Up @@ -43,4 +46,32 @@ protected function createTimerInterrupt($delay = 0.01)
$loop->stop();
});
}

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);
}
}

public function assertEqualsDelta($expected, $actual, $delta)
{
if (method_exists($this, 'assertEqualsWithDelta')) {
// PHPUnit 7.5+
$this->assertEqualsWithDelta($expected, $actual, $delta);
} else {
// legacy PHPUnit 4 - PHPUnit 7.5
$this->assertEquals($expected, $actual, '', $delta);
}
}
}