From 575816a797afe985d549c9c9c2ae50b8e4486cb2 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Wed, 14 Oct 2020 11:03:47 +0200 Subject: [PATCH 1/2] Run tests on PHPUnit 9 --- tests/AssocDecoderTest.php | 5 ++++- tests/DecoderTest.php | 5 ++++- tests/EncoderTest.php | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/AssocDecoderTest.php b/tests/AssocDecoderTest.php index a5e950f..91003e0 100644 --- a/tests/AssocDecoderTest.php +++ b/tests/AssocDecoderTest.php @@ -10,7 +10,10 @@ class AssocDecoderTest extends TestCase private $input; private $decoder; - public function setUp() + /** + * @before + */ + public function setUpDecoder() { $stream = fopen('php://temp', 'r'); $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); diff --git a/tests/DecoderTest.php b/tests/DecoderTest.php index 12ca45e..0eea26c 100644 --- a/tests/DecoderTest.php +++ b/tests/DecoderTest.php @@ -10,7 +10,10 @@ class DecoderTest extends TestCase private $input; private $decoder; - public function setUp() + /** + * @before + */ + public function setUpDecoder() { $stream = fopen('php://temp', 'r'); $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); diff --git a/tests/EncoderTest.php b/tests/EncoderTest.php index 6f4cf50..c3a7182 100644 --- a/tests/EncoderTest.php +++ b/tests/EncoderTest.php @@ -10,7 +10,10 @@ class EncoderTest extends TestCase private $output; private $encoder; - public function setUp() + /** + * @before + */ + public function setUpEncoder() { $stream = fopen('php://temp', 'r+'); $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); From f828a0c331015dda475852f00c48f6259dcaafa5 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Wed, 14 Oct 2020 11:03:57 +0200 Subject: [PATCH 2/2] Update PHPUnit configuration schema for PHPUnit 9.3 --- .gitattributes | 1 + .travis.yml | 9 ++++----- composer.json | 2 +- phpunit.xml.dist | 17 +++++++++++------ phpunit.xml.legacy | 18 ++++++++++++++++++ tests/TestCase.php | 8 +++++++- 6 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 phpunit.xml.legacy diff --git a/.gitattributes b/.gitattributes index 0925d33..eccc763 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,4 +3,5 @@ /.travis.yml export-ignore /examples/ export-ignore /phpunit.xml.dist export-ignore +/phpunit.xml.legacy export-ignore /tests/ export-ignore diff --git a/.travis.yml b/.travis.yml index d0dc010..e10eede 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -21,10 +21,9 @@ matrix: allow_failures: - php: hhvm-3.18 -sudo: false - 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 diff --git a/composer.json b/composer.json index 19610ad..01e37b8 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "react/stream": "^1.0 || ^0.7 || ^0.6" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^6.0 || ^5.7 || ^4.8.35", + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", "react/child-process": "^0.6", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5fb5bb4..c33fd5b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,19 @@ - + + - + ./tests/ - - + + ./src/ - - + + diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy new file mode 100644 index 0000000..358b991 --- /dev/null +++ b/phpunit.xml.legacy @@ -0,0 +1,18 @@ + + + + + + + ./tests/ + + + + + ./src/ + + + diff --git a/tests/TestCase.php b/tests/TestCase.php index c64e992..6d796a6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -39,6 +39,12 @@ protected function expectCallableOnceWith($value) protected function createCallableMock() { - return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) { + // PHPUnit 9+ + return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock(); + } else { + // legacy PHPUnit 4 - PHPUnit 8 + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + } } }