From fa64326053c76c8cf3335ce604279e48b09470dd Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Tue, 21 Jul 2020 10:39:59 +0200 Subject: [PATCH 1/4] Run tests on PHPUnit 9 --- .travis.yml | 2 +- composer.json | 9 ++++--- phpunit.xml.dist | 1 - tests/React/Promise/DeferredTest.php | 2 +- tests/React/Promise/ErrorCollector.php | 2 +- tests/React/Promise/PromiseTest.php | 4 ++-- tests/React/Promise/Stub/CallableStub.php | 10 -------- tests/React/Promise/TestCase.php | 29 +++++++++++++++++++---- 8 files changed, 36 insertions(+), 23 deletions(-) delete mode 100644 tests/React/Promise/Stub/CallableStub.php diff --git a/.travis.yml b/.travis.yml index eb5a9cdc..90d9e19f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ install: - composer install --prefer-source script: - - phpunit -v --coverage-text + - vendor/bin/phpunit --coverage-text diff --git a/composer.json b/composer.json index 7e1caffb..1f1b7003 100644 --- a/composer.json +++ b/composer.json @@ -5,9 +5,6 @@ "authors": [ {"name": "Jan Sorgalla", "email": "jsorgalla@gmail.com"} ], - "require": { - "php": ">=5.3.3" - }, "autoload": { "psr-0": { "React\\Promise": "src/" @@ -18,5 +15,11 @@ "branch-alias": { "dev-master": "1.1-dev" } + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0f98aea7..37382735 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="tests/bootstrap.php" > diff --git a/tests/React/Promise/DeferredTest.php b/tests/React/Promise/DeferredTest.php index b5c2fdba..f13c6997 100644 --- a/tests/React/Promise/DeferredTest.php +++ b/tests/React/Promise/DeferredTest.php @@ -204,10 +204,10 @@ public function shouldInvokeCancellationHandleWhenCancellingAllDerived() /** * @test - * @expectedException InvalidArgumentException */ public function shouldThrowIfCancellerIsNotACallable() { + $this->setExpectedException('InvalidArgumentException'); new Deferred(false); } } diff --git a/tests/React/Promise/ErrorCollector.php b/tests/React/Promise/ErrorCollector.php index 648ab68a..3bf9a604 100644 --- a/tests/React/Promise/ErrorCollector.php +++ b/tests/React/Promise/ErrorCollector.php @@ -33,6 +33,6 @@ public function assertCollectedError($errstr, $errno) $message = 'Error with level ' . $errno . ' and message "' . $errstr . '" not found in ' . var_export($this->errors, true); - throw new \PHPUnit_Framework_AssertionFailedError($message); + throw new \PHPUnit\Framework\AssertionFailedError($message); } } diff --git a/tests/React/Promise/PromiseTest.php b/tests/React/Promise/PromiseTest.php index e6f22fbd..474a562d 100644 --- a/tests/React/Promise/PromiseTest.php +++ b/tests/React/Promise/PromiseTest.php @@ -10,7 +10,7 @@ class PromiseTest extends TestCase /** @test */ public function shouldThrowIfResolverIsNotACallable() { - $this->setExpectedException('\InvalidArgumentException'); + $this->setExpectedException('InvalidArgumentException'); new Promise(null); } @@ -93,10 +93,10 @@ public function shouldInvokeCancellationHandlerAndStayPendingWhenCallingCancel() /** * @test - * @expectedException InvalidArgumentException */ public function shouldThrowIfCancellerIsNotACallable() { + $this->setExpectedException('InvalidArgumentException'); new Promise(function () { }, false); } } diff --git a/tests/React/Promise/Stub/CallableStub.php b/tests/React/Promise/Stub/CallableStub.php deleted file mode 100644 index 01208933..00000000 --- a/tests/React/Promise/Stub/CallableStub.php +++ /dev/null @@ -1,10 +0,0 @@ -getMockBuilder('React\\Promise\Stub\CallableStub') - ->getMock(); + if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) { + // PHPUnit 9+ + return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock(); + } else { + // legacy PHPUnit 4 - PHPUnit 9 + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + } } public function invalidCallbackDataProvider() @@ -52,4 +56,21 @@ public function invalidCallbackDataProvider() 'falsey' => array(0) ); } + + 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); + } + } } From 34e307d183264b14745bf1e566e88a57cfa29306 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Tue, 21 Jul 2020 10:50:41 +0200 Subject: [PATCH 2/4] Run tests on PHP 7.4 and simplify test matrix --- .travis.yml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 90d9e19f..e1421bc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,26 @@ language: php -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - - 7.0 - - hhvm +# lock distro so new future defaults will not break the build +dist: trusty -before_install: - - composer self-update +jobs: + include: + - php: 5.3 + dist: precise + - php: 5.4 + - php: 5.5 + - php: 5.6 + - php: 7.0 + - php: 7.1 + - php: 7.2 + - php: 7.3 + - php: 7.4 + - php: hhvm-3.18 + allow_failures: + - php: hhvm-3.18 install: - - composer install --prefer-source + - composer install script: - vendor/bin/phpunit --coverage-text From 1a88c8c318f1488a0082fcb3e89b14df132ec486 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Tue, 21 Jul 2020 12:25:16 +0200 Subject: [PATCH 3/4] Clean up test suite --- composer.json | 21 ++++++++++++------- phpunit.xml.dist | 11 +--------- tests/React/Promise/DeferredProgressTest.php | 4 +++- tests/React/Promise/DeferredPromiseTest.php | 4 +++- tests/React/Promise/DeferredRejectTest.php | 6 +++++- tests/React/Promise/DeferredResolveTest.php | 7 ++++++- tests/React/Promise/DeferredResolverTest.php | 4 +++- tests/React/Promise/DeferredTest.php | 4 +++- tests/React/Promise/ErrorCollector.php | 2 +- tests/React/Promise/FulfilledPromiseTest.php | 5 ++++- tests/React/Promise/LazyPromiseTest.php | 6 +++++- tests/React/Promise/PromiseTest.php | 4 +++- tests/React/Promise/RejectedPromiseTest.php | 5 ++++- tests/React/Promise/TestCase.php | 2 +- tests/React/Promise/UtilPromiseForTest.php | 6 +++++- .../Promise/UtilRejectedPromiseForTest.php | 6 +++++- tests/React/Promise/WhenAllTest.php | 4 +++- tests/React/Promise/WhenAnyTest.php | 5 ++++- tests/React/Promise/WhenLazyTest.php | 4 +++- tests/React/Promise/WhenMapTest.php | 4 +++- tests/React/Promise/WhenReduceTest.php | 5 ++++- tests/React/Promise/WhenRejectTest.php | 5 ++++- tests/React/Promise/WhenResolveTest.php | 5 ++++- tests/React/Promise/WhenSomeTest.php | 4 +++- tests/bootstrap.php | 4 ---- 25 files changed, 93 insertions(+), 44 deletions(-) delete mode 100644 tests/bootstrap.php diff --git a/composer.json b/composer.json index 1f1b7003..2e1f1cd8 100644 --- a/composer.json +++ b/composer.json @@ -5,21 +5,26 @@ "authors": [ {"name": "Jan Sorgalla", "email": "jsorgalla@gmail.com"} ], + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35" + }, "autoload": { - "psr-0": { - "React\\Promise": "src/" + "psr-4": { + "React\\Promise\\": "src/React/Promise/" }, "files": ["src/React/Promise/functions_include.php"] }, + "autoload-dev": { + "psr-4": { + "React\\Tests\\Promise\\": "tests/React/Promise/" + } + }, "extra": { "branch-alias": { "dev-master": "1.1-dev" } - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 37382735..8ce12cfa 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,6 @@ - + ./tests/React/Promise/ diff --git a/tests/React/Promise/DeferredProgressTest.php b/tests/React/Promise/DeferredProgressTest.php index 838105da..44875781 100644 --- a/tests/React/Promise/DeferredProgressTest.php +++ b/tests/React/Promise/DeferredProgressTest.php @@ -1,6 +1,8 @@ add('React\Promise', __DIR__); From 5b8f273e6615c039189193c4fd3653ae58cd1d21 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Tue, 21 Jul 2020 12:27:08 +0200 Subject: [PATCH 4/4] Add .gitattributes to exclude dev files from exports --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..0925d33a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/examples/ export-ignore +/phpunit.xml.dist export-ignore +/tests/ export-ignore