Skip to content

Commit

Permalink
Merge pull request #163 from clue-labs/2x-php7.4
Browse files Browse the repository at this point in the history
Run tests on PHP 7.4 (backport to v2.x) and update PHPUnit test setup
  • Loading branch information
jsor committed Mar 5, 2020
2 parents 7c98fda + ac2b6a7 commit 0f37290
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,9 @@ php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- nightly # ignore errors, see below
- hhvm # ignore errors, see below

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -9,7 +9,7 @@
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "^7.0 || ^6.5 || ^5.7 || ^4.8.36"
},
"autoload": {
"psr-4": {
Expand All @@ -19,7 +19,7 @@
},
"autoload-dev": {
"psr-4": {
"React\\Promise\\": "tests/fixtures"
"React\\Promise\\": ["tests", "tests/fixtures"]
}
},
"keywords": [
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Expand Up @@ -8,8 +8,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Promise Test Suite">
Expand Down
4 changes: 4 additions & 0 deletions tests/DeferredTest.php
Expand Up @@ -44,6 +44,8 @@ public function progressIsAnAliasForNotify()
public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerRejectsWithException()
{
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on

$deferred = new Deferred(function ($resolve, $reject) {
$reject(new \Exception('foo'));
});
Expand All @@ -57,6 +59,8 @@ public function shouldRejectWithoutCreatingGarbageCyclesIfCancellerRejectsWithEx
public function shouldRejectWithoutCreatingGarbageCyclesIfParentCancellerRejectsWithException()
{
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on

$deferred = new Deferred(function ($resolve, $reject) {
$reject(new \Exception('foo'));
});
Expand Down
2 changes: 2 additions & 0 deletions tests/FulfilledPromiseTest.php
Expand Up @@ -52,6 +52,8 @@ public function shouldThrowExceptionIfConstructedWithAPromise()
public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithAlwaysFollowers()
{
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on

$promise = new FulfilledPromise(1);
$promise->always(function () {
throw new \RuntimeException();
Expand Down
2 changes: 2 additions & 0 deletions tests/PromiseTest.php
Expand Up @@ -52,6 +52,8 @@ public function shouldRejectIfResolverThrowsException()
public function shouldResolveWithoutCreatingGarbageCyclesIfResolverResolvesWithException()
{
gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on

$promise = new Promise(function ($resolve) {
$resolve(new \Exception('foo'));
});
Expand Down
10 changes: 0 additions & 10 deletions tests/Stub/CallableStub.php

This file was deleted.

23 changes: 19 additions & 4 deletions tests/TestCase.php
Expand Up @@ -2,7 +2,7 @@

namespace React\Promise;

class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends \PHPUnit\Framework\TestCase
{
public function expectCallableExactly($amount)
{
Expand Down Expand Up @@ -36,8 +36,23 @@ public function expectCallableNever()

public function createCallableMock()
{
return $this
->getMockBuilder('React\\Promise\Stub\CallableStub')
->getMock();
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
}

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);
}
}
}
7 changes: 0 additions & 7 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit 0f37290

Please sign in to comment.