From d6978a2368dfcba1754744ce361761191b5c2702 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Wed, 14 Oct 2020 11:40:00 +0200 Subject: [PATCH 1/2] Run tests on PHPUnit 9 --- tests/EventSourceTest.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/EventSourceTest.php b/tests/EventSourceTest.php index 3b21c92..ecf7f2b 100644 --- a/tests/EventSourceTest.php +++ b/tests/EventSourceTest.php @@ -13,30 +13,24 @@ class EventSourceTest extends TestCase { - /** - * @expectedException InvalidArgumentException - */ public function testConstructorThrowsIfFirstArgumentIsNotAnUri() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->setExpectedException('InvalidArgumentException'); new EventSource('///', $loop); } - /** - * @expectedException InvalidArgumentException - */ public function testConstructorThrowsIfUriArgumentDoesNotIncludeScheme() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->setExpectedException('InvalidArgumentException'); new EventSource('example.com', $loop); } - /** - * @expectedException InvalidArgumentException - */ public function testConstructorThrowsIfUriArgumentIncludesInvalidScheme() { $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); + $this->setExpectedException('InvalidArgumentException'); new EventSource('ftp://example.com', $loop); } @@ -620,4 +614,21 @@ public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStre $this->assertNotNull($timerReconnect); $timerReconnect(); } + + public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null) + { + if (method_exists($this, 'expectException')) { + // PHPUnit 5.2+ + $this->expectException($exception); + if ($exceptionMessage !== '') { + $this->expectExceptionMessage($exceptionMessage); + } + if ($exceptionCode !== null) { + $this->expectExceptionCode($exceptionCode); + } + } else { + // legacy PHPUnit 4 - PHPUnit 5.1 + parent::setExpectedException($exception, $exceptionMessage, $exceptionCode); + } + } } From 36148907be2fa2c921d5f69c39656daf184e7116 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Wed, 14 Oct 2020 11:40:21 +0200 Subject: [PATCH 2/2] Update PHPUnit configuration schema for PHPUnit 9.3 --- .gitattributes | 1 + .travis.yml | 7 +++---- composer.json | 2 +- phpunit.xml.dist | 15 ++++++++++----- phpunit.xml.legacy | 18 ++++++++++++++++++ 5 files changed, 33 insertions(+), 10 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 4239215..a0d2710 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,9 @@ php: # lock distro so new future defaults will not break the build dist: trusty -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 2e77766..fe343d0 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,6 @@ "react/http": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7b458f2..7822452 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..eb71b61 --- /dev/null +++ b/phpunit.xml.legacy @@ -0,0 +1,18 @@ + + + + + + + ./tests/ + + + + + ./src/ + + +