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 PHP 7.4 (backport to v2.x) and update PHPUnit test setup #163

Merged
merged 2 commits into from
Mar 5, 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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.