From 2801b852c240b95a9b4e8f737836e00ad6b560fa Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 23 Nov 2020 11:28:50 +0100 Subject: [PATCH 1/3] Run tests on PHPUnit 9 --- composer.json | 2 +- tests/FactoryTest.php | 15 +++++++++++---- tests/SocketTest.php | 5 ++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 09453b2..fadd55d 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,6 @@ "php": ">=5.3" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^6.0 || ^5.2 || ^4.8.35" + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" } } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 0f4fb12..acea175 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -12,7 +12,10 @@ class FactoryTest extends TestCase */ protected $factory; - public function setUp() + /** + * @before + */ + public function setUpFactory() { $this->factory = new Factory(); } @@ -409,13 +412,13 @@ public function testCreateListenRandom() * * @param Socket $socket * @depends testCreateListenRandom - * @expectedException Exception */ public function testCreateListenInUseFails(Socket $socket) { $address = $socket->getSockName(); $port = substr($address, strrpos($address, ':') + 1); + $this->setExpectedException('Exception'); $this->factory->createListen($port); } @@ -488,15 +491,19 @@ public function testCreateFromStringInvalid() $this->fail('Creating socket for invalid scheme should fail'); } - public function setExpectedException($exception, $message = '', $code = 0) + public function setExpectedException($exception, $message = null, $code = null) { if (method_exists($this, 'expectException')) { + // PHPUnit 5.2+ $this->expectException($exception); if ($message !== null) { $this->expectExceptionMessage($message); } - $this->expectExceptionCode($code); + if ($code !== null) { + $this->expectExceptionCode($code); + } } else { + // legacy PHPUnit 4 - PHPUnit 5.1 parent::setExpectedException($exception, $message, $code); } } diff --git a/tests/SocketTest.php b/tests/SocketTest.php index a792bb9..8ce0976 100644 --- a/tests/SocketTest.php +++ b/tests/SocketTest.php @@ -12,7 +12,10 @@ class SocketTest extends TestCase */ protected $factory; - public function setUp() + /** + * @before + */ + public function setUpFactory() { $this->factory = new Factory(); } From 229a35c80b857107d977ef7df456cc8752e9adfe Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 23 Nov 2020 11:40:30 +0100 Subject: [PATCH 2/3] Update PHPUnit configuration schema for PHPUnit 9.3 --- .travis.yml | 11 +++++------ phpunit.xml.dist | 18 +++++++++--------- phpunit.xml.legacy | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 phpunit.xml.legacy diff --git a/.travis.yml b/.travis.yml index 6957fea..2b01760 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 @@ -16,7 +16,7 @@ matrix: - php: 7.3 - php: 7.4 - php: hhvm-3.18 - install: composer require phpunit/phpunit:^5 --dev --no-interaction + install: composer require phpunit/phpunit:^5 --dev - name: "Windows" os: windows language: shell # no built-in php support @@ -30,10 +30,9 @@ matrix: - php: hhvm-3.18 - os: windows -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/phpunit.xml.dist b/phpunit.xml.dist index 6f8fe17..08fd8ec 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,19 @@ - + + cacheResult="false"> ./tests/ - - + + ./src/ - - + + diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy new file mode 100644 index 0000000..7c9c435 --- /dev/null +++ b/phpunit.xml.legacy @@ -0,0 +1,18 @@ + + + + + + + ./tests/ + + + + + ./src/ + + + From 3bb1f5e7a9191a9f4762c0609f46879ae4ee569f Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 23 Nov 2020 11:42:30 +0100 Subject: [PATCH 3/3] Add .gitattributes to exclude dev files from exports --- .gitattributes | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..eccc763 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/examples/ export-ignore +/phpunit.xml.dist export-ignore +/phpunit.xml.legacy export-ignore +/tests/ export-ignore