From 1150e0ad458b82c9aa2946681cf17d13e43d4b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 4 Mar 2020 11:44:41 +0100 Subject: [PATCH 1/2] Update test suite to PHPUnit 7 and legacy PHPUnit versions --- composer.json | 4 ++-- phpunit.xml.dist | 3 +-- tests/Stub/CallableStub.php | 10 ---------- tests/TestCase.php | 23 +++++++++++++++++++---- tests/bootstrap.php | 7 ------- 5 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 tests/Stub/CallableStub.php delete mode 100644 tests/bootstrap.php diff --git a/composer.json b/composer.json index 2fc48091..b3e723a7 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -19,7 +19,7 @@ }, "autoload-dev": { "psr-4": { - "React\\Promise\\": "tests/fixtures" + "React\\Promise\\": ["tests", "tests/fixtures"] } }, "keywords": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b9a689d7..3d184322 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,8 +8,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" - bootstrap="tests/bootstrap.php" + bootstrap="vendor/autoload.php" > diff --git a/tests/Stub/CallableStub.php b/tests/Stub/CallableStub.php deleted file mode 100644 index 01208933..00000000 --- a/tests/Stub/CallableStub.php +++ /dev/null @@ -1,10 +0,0 @@ -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); + } } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 9b7f872a..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,7 +0,0 @@ -addPsr4('React\\Promise\\', __DIR__); From ac2b6a7ede8dd244d04ea0742fc954515f34f5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 4 Mar 2020 11:53:55 +0100 Subject: [PATCH 2/2] Run tests on PHP 7.4 --- .travis.yml | 3 +++ tests/DeferredTest.php | 4 ++++ tests/FulfilledPromiseTest.php | 2 ++ tests/PromiseTest.php | 2 ++ 4 files changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index bcbe642f..da0fcd0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/tests/DeferredTest.php b/tests/DeferredTest.php index 8ee40b8a..b11199b8 100644 --- a/tests/DeferredTest.php +++ b/tests/DeferredTest.php @@ -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')); }); @@ -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')); }); diff --git a/tests/FulfilledPromiseTest.php b/tests/FulfilledPromiseTest.php index f5a2da80..d814c2a2 100644 --- a/tests/FulfilledPromiseTest.php +++ b/tests/FulfilledPromiseTest.php @@ -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(); diff --git a/tests/PromiseTest.php b/tests/PromiseTest.php index 344b4114..4778129f 100644 --- a/tests/PromiseTest.php +++ b/tests/PromiseTest.php @@ -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')); });