From 3c2506ed44035b82ed4745ec0a8c5ddb40f142b0 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 12 Oct 2020 11:30:35 +0200 Subject: [PATCH 1/3] Run tests on PHPUnit 9 --- composer.json | 2 +- tests/FunctionalTest.php | 83 ++++++++++++++++------------ tests/Protocol/ClientDecoderTest.php | 21 ++++++- 3 files changed, 67 insertions(+), 39 deletions(-) diff --git a/composer.json b/composer.json index 99722cd..8c0f233 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,6 @@ }, "require-dev": { "clue/block-react": "^1.0", - "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" + "phpunit/phpunit": "^9.0 || ^6.4 || ^5.7 || ^4.8.35" } } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 41d5b34..ce68c12 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -29,12 +29,18 @@ class FunctionalTest extends TestCase // download WSDL file only once for all test cases private static $wsdl; - public static function setUpBeforeClass() + /** + * @beforeClass + */ + public static function setUpFileBeforeClass() { self::$wsdl = file_get_contents('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'); } - public function setUp() + /** + * @before + */ + public function setUpClient() { $this->loop = \React\EventLoop\Factory::create(); $this->client = new Client(new Browser($this->loop), self::$wsdl); @@ -51,7 +57,7 @@ public function testBlzService() $result = Block\await($promise, $this->loop); - $this->assertInternalType('object', $result); + $this->assertIsTypeObject($result); $this->assertTrue(isset($result->details)); $this->assertTrue(isset($result->details->bic)); } @@ -93,7 +99,7 @@ public function testBlzServiceWithSoapV12() $result = Block\await($promise, $this->loop); - $this->assertInternalType('object', $result); + $this->assertIsTypeObject($result); $this->assertTrue(isset($result->details)); $this->assertTrue(isset($result->details->bic)); } @@ -113,15 +119,11 @@ public function testBlzServiceNonWsdlModeReturnedWithoutOuterResultStructure() $result = Block\await($promise, $this->loop); - $this->assertInternalType('object', $result); + $this->assertIsTypeObject($result); $this->assertFalse(isset($result->details)); $this->assertTrue(isset($result->bic)); } - /** - * @expectedException RuntimeException - * @expectedExeptionMessage redirects - */ public function testBlzServiceWithRedirectLocationRejectsWithRuntimeException() { $this->client = new Client(new Browser($this->loop), null, array( @@ -132,39 +134,30 @@ public function testBlzServiceWithRedirectLocationRejectsWithRuntimeException() $api = new Proxy($this->client); $promise = $api->getBank('a'); + $this->setExpectedException('RuntimeException', 'redirects'); $result = Block\await($promise, $this->loop); } - /** - * @expectedException SoapFault - * @expectedExeptionMessage Keine Bank zur BLZ invalid gefunden! - */ public function testBlzServiceWithInvalidBlzRejectsWithSoapFault() { $api = new Proxy($this->client); $promise = $api->getBank(array('blz' => 'invalid')); + $this->setExpectedException('SoapFault', 'Keine Bank zur BLZ invalid gefunden!'); Block\await($promise, $this->loop); } - /** - * @expectedException SoapFault - * @expectedExceptionMessage Function ("doesNotExist") is not a valid method for this service - */ public function testBlzServiceWithInvalidMethodRejectsWithSoapFault() { $api = new Proxy($this->client); $promise = $api->doesNotExist(); + $this->setExpectedException('SoapFault', 'Function ("doesNotExist") is not a valid method for this service'); Block\await($promise, $this->loop); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage cancelled - */ public function testCancelMethodRejectsWithRuntimeException() { $api = new Proxy($this->client); @@ -172,13 +165,10 @@ public function testCancelMethodRejectsWithRuntimeException() $promise = $api->getBank(array('blz' => '12070000')); $promise->cancel(); + $this->setExpectedException('RuntimeException', 'cancelled'); Block\await($promise, $this->loop); } - /** - * @expectedException RuntimeException - * @expectedExceptionMessage timed out - */ public function testTimeoutRejectsWithRuntimeException() { $browser = new Browser($this->loop); @@ -191,6 +181,7 @@ public function testTimeoutRejectsWithRuntimeException() $promise = $api->getBank(array('blz' => '12070000')); + $this->setExpectedException('RuntimeException', 'timed out'); Block\await($promise, $this->loop); } @@ -205,19 +196,15 @@ public function testGetLocationForFunctionNumber() $this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(0)); } - /** - * @expectedException SoapFault - */ public function testGetLocationOfUnknownFunctionNameFails() { + $this->setExpectedException('SoapFault'); $this->client->getLocation('unknown'); } - /** - * @expectedException SoapFault - */ public function testGetLocationForUnknownFunctionNumberFails() { + $this->setExpectedException('SoapFault'); $this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100)); } @@ -239,15 +226,13 @@ public function testWithLocationReturnsUpdatedClient() $this->assertEquals($original, $this->client->getLocation(0)); } - /** - * @expectedException RuntimeException - */ public function testWithLocationInvalidRejectsWithRuntimeException() { $api = new Proxy($this->client->withLocation('http://nonsense.invalid')); $promise = $api->getBank(array('blz' => '12070000')); + $this->setExpectedException('RuntimeException'); Block\await($promise, $this->loop); } @@ -261,6 +246,34 @@ public function testWithLocationRestoredToOriginalResolves() $promise = $api->getBank(array('blz' => '12070000')); $result = Block\await($promise, $this->loop); - $this->assertInternalType('object', $result); + $this->assertIsTypeObject($result); + } + + public function assertIsTypeObject($actual) + { + if (method_exists($this, 'assertInternalType')) { + // legacy PHPUnit 4 - PHPUnit 7.5 + $this->assertInternalType('object', $actual); + } else { + // PHPUnit 7.5+ + $this->assertIsObject($actual); + } + } + + 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/Protocol/ClientDecoderTest.php b/tests/Protocol/ClientDecoderTest.php index e4ae4f2..96a9c18 100644 --- a/tests/Protocol/ClientDecoderTest.php +++ b/tests/Protocol/ClientDecoderTest.php @@ -5,12 +5,10 @@ class ClientDecoderTest extends TestCase { - /** - * @expectedException SoapFault - */ public function testDecodeThrowsSoapFaultForInvalidResponse() { $decoder = new ClientDecoder(null, array('location' => '1', 'uri' => '2')); + $this->setExpectedException('SoapFault'); $decoder->decode('anything', 'invalid'); } @@ -32,4 +30,21 @@ public function testDecodeMessageToObjectNonWsdl() $this->assertEquals($expected, $res); } + + 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 b889dc6a6878c869bb83416ff4b6e815dbe21614 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 12 Oct 2020 11:50:30 +0200 Subject: [PATCH 2/3] Use httpbingo intsead of httpbin cause of outdated service --- tests/FunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index ce68c12..0abd814 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -127,7 +127,7 @@ public function testBlzServiceNonWsdlModeReturnedWithoutOuterResultStructure() public function testBlzServiceWithRedirectLocationRejectsWithRuntimeException() { $this->client = new Client(new Browser($this->loop), null, array( - 'location' => 'http://httpbin.org/redirect-to?url=' . rawurlencode('http://www.thomas-bayer.com/axis2/services/BLZService'), + 'location' => 'http://httpbingo.org/redirect-to?url=' . rawurlencode('http://www.thomas-bayer.com/axis2/services/BLZService'), 'uri' => 'http://thomas-bayer.com/blz/', )); From a0c0ceb0607ee2484b95cd32ebc35e755d900536 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 12 Oct 2020 12:00:37 +0200 Subject: [PATCH 3/3] Update PHPUnit configuration schema for PHPUnit 9.3 --- .gitattributes | 1 + .travis.yml | 9 ++++----- composer.json | 2 +- phpunit.xml.dist | 19 ++++++++++++------- phpunit.xml.legacy | 18 ++++++++++++++++++ 5 files changed, 36 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 0a5430e..5623330 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 @@ -19,10 +19,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 8c0f233..0a4b2b3 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,6 @@ }, "require-dev": { "clue/block-react": "^1.0", - "phpunit/phpunit": "^9.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 bd304c3..9f2d400 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,19 @@ - + + - + ./tests/ - - + + ./src/ - - - \ No newline at end of file + + + diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy new file mode 100644 index 0000000..16ff755 --- /dev/null +++ b/phpunit.xml.legacy @@ -0,0 +1,18 @@ + + + + + + + ./tests/ + + + + + ./src/ + + +