From 5ecd2a004be37ebb27802a55acc7bde3220c4ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 28 Oct 2020 07:56:03 +0100 Subject: [PATCH 1/3] Fix executing skipped tests when xdebug is loaded --- tests/ClientTest.php | 29 +++++++++++++++++++++------- tests/Protocol/ClientEncoderTest.php | 25 ++++++++++++++++++------ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index e4afa69..ce8c3da 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -8,10 +8,6 @@ class ClientTest extends TestCase { - - /** - * @expectedException SoapFault - */ public function testConstructorThrowsWhenUrlIsInvalid() { if (extension_loaded('xdebug')) { @@ -19,15 +15,18 @@ public function testConstructorThrowsWhenUrlIsInvalid() } $browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock(); + $browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf(); + $browser->expects($this->once())->method('withFollowRedirects')->willReturnSelf(); + $wsdl = 'invalid'; - $client = new Client($browser, $wsdl); + $this->setExpectedException('SoapFault'); + new Client($browser, $wsdl); } public function testNonWsdlClientReturnsSameLocationOptionForAnyFunction() { $browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock(); - $browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf(); $browser->expects($this->once())->method('withFollowRedirects')->willReturnSelf(); @@ -39,7 +38,6 @@ public function testNonWsdlClientReturnsSameLocationOptionForAnyFunction() public function testNonWsdlClientReturnsNoTypesAndFunctions() { $browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock(); - $browser->expects($this->once())->method('withRejectErrorResponse')->willReturnSelf(); $browser->expects($this->once())->method('withFollowRedirects')->willReturnSelf(); @@ -61,4 +59,21 @@ public function testNonWsdlClientSendsPostRequestToGivenLocationForAnySoapCall() $client->soapCall('ping', array()); } + + 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/ClientEncoderTest.php b/tests/Protocol/ClientEncoderTest.php index 550d680..6c29941 100644 --- a/tests/Protocol/ClientEncoderTest.php +++ b/tests/Protocol/ClientEncoderTest.php @@ -36,27 +36,23 @@ public function testEncodeCreatesRequestForNonWsdlRpcFunctionWithSoapV12() $this->assertFalse($request->hasHeader('SOAPAction')); } - /** - * @expectedException SoapFault - */ public function testConstructorThrowsWhenUrlIsInvalid() { if (extension_loaded('xdebug')) { $this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug is loaded'); } + $this->setExpectedException('SoapFault'); new ClientEncoder('invalid'); } - /** - * @expectedException SoapFault - */ public function testConstructorThrowsWhenNonWsdlDoesNotDefineLocationAndUri() { if (extension_loaded('xdebug')) { $this->markTestSkipped('Invalid non-WSDL mode causes a fatal error when ext-xdebug is loaded'); } + $this->setExpectedException('SoapFault'); new ClientEncoder(null); } @@ -80,4 +76,21 @@ public function testEncodeRequestForBlzServiceNonWsdlMode() $this->assertEquals($expected, (string)$request->getBody()); } + + 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 7d1095ba8f365f82da4de9469156730ec425e571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 28 Oct 2020 08:10:23 +0100 Subject: [PATCH 2/3] Clean up test suite to simplify checking exceptions --- tests/ClientTest.php | 19 +------------ tests/FunctionalTest.php | 40 ++++++++++------------------ tests/Protocol/ClientDecoderTest.php | 20 ++------------ tests/Protocol/ClientEncoderTest.php | 21 ++------------- 4 files changed, 19 insertions(+), 81 deletions(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index ce8c3da..895d3ce 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -20,7 +20,7 @@ public function testConstructorThrowsWhenUrlIsInvalid() $wsdl = 'invalid'; - $this->setExpectedException('SoapFault'); + $this->expectException(\SoapFault::class); new Client($browser, $wsdl); } @@ -59,21 +59,4 @@ public function testNonWsdlClientSendsPostRequestToGivenLocationForAnySoapCall() $client->soapCall('ping', array()); } - - 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/FunctionalTest.php b/tests/FunctionalTest.php index 2610eb8..0f109d0 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -134,8 +134,9 @@ public function testBlzServiceWithRedirectLocationRejectsWithRuntimeException() $api = new Proxy($this->client); $promise = $api->getBank('a'); - $this->setExpectedException('RuntimeException', 'redirects'); - $result = Block\await($promise, $this->loop); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('redirects'); + Block\await($promise, $this->loop); } public function testBlzServiceWithInvalidBlzRejectsWithSoapFault() @@ -144,7 +145,8 @@ public function testBlzServiceWithInvalidBlzRejectsWithSoapFault() $promise = $api->getBank(array('blz' => 'invalid')); - $this->setExpectedException('SoapFault', 'Keine Bank zur BLZ invalid gefunden!'); + $this->expectException(\SoapFault::class); + $this->expectExceptionMessage('Keine Bank zur BLZ invalid gefunden!'); Block\await($promise, $this->loop); } @@ -154,7 +156,8 @@ public function testBlzServiceWithInvalidMethodRejectsWithSoapFault() $promise = $api->doesNotExist(); - $this->setExpectedException('SoapFault', 'Function ("doesNotExist") is not a valid method for this service'); + $this->expectException(\SoapFault::class); + $this->expectExceptionMessage('Function ("doesNotExist") is not a valid method for this service'); Block\await($promise, $this->loop); } @@ -165,7 +168,8 @@ public function testCancelMethodRejectsWithRuntimeException() $promise = $api->getBank(array('blz' => '12070000')); $promise->cancel(); - $this->setExpectedException('RuntimeException', 'cancelled'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('cancelled'); Block\await($promise, $this->loop); } @@ -179,7 +183,8 @@ public function testTimeoutRejectsWithRuntimeException() $promise = $api->getBank(array('blz' => '12070000')); - $this->setExpectedException('RuntimeException', 'timed out'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('timed out'); Block\await($promise, $this->loop); } @@ -196,13 +201,13 @@ public function testGetLocationForFunctionNumber() public function testGetLocationOfUnknownFunctionNameFails() { - $this->setExpectedException('SoapFault'); + $this->expectException(\SoapFault::class); $this->client->getLocation('unknown'); } public function testGetLocationForUnknownFunctionNumberFails() { - $this->setExpectedException('SoapFault'); + $this->expectException(\SoapFault::class); $this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100)); } @@ -230,7 +235,7 @@ public function testWithLocationInvalidRejectsWithRuntimeException() $promise = $api->getBank(array('blz' => '12070000')); - $this->setExpectedException('RuntimeException'); + $this->expectException(\RuntimeException::class); Block\await($promise, $this->loop); } @@ -257,21 +262,4 @@ public function assertIsTypeObject($actual) $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 96a9c18..f8d0f34 100644 --- a/tests/Protocol/ClientDecoderTest.php +++ b/tests/Protocol/ClientDecoderTest.php @@ -8,7 +8,8 @@ class ClientDecoderTest extends TestCase public function testDecodeThrowsSoapFaultForInvalidResponse() { $decoder = new ClientDecoder(null, array('location' => '1', 'uri' => '2')); - $this->setExpectedException('SoapFault'); + + $this->expectException(\SoapFault::class); $decoder->decode('anything', 'invalid'); } @@ -30,21 +31,4 @@ 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); - } - } } diff --git a/tests/Protocol/ClientEncoderTest.php b/tests/Protocol/ClientEncoderTest.php index 6c29941..cd9dd23 100644 --- a/tests/Protocol/ClientEncoderTest.php +++ b/tests/Protocol/ClientEncoderTest.php @@ -42,7 +42,7 @@ public function testConstructorThrowsWhenUrlIsInvalid() $this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug is loaded'); } - $this->setExpectedException('SoapFault'); + $this->expectException(\SoapFault::class); new ClientEncoder('invalid'); } @@ -52,7 +52,7 @@ public function testConstructorThrowsWhenNonWsdlDoesNotDefineLocationAndUri() $this->markTestSkipped('Invalid non-WSDL mode causes a fatal error when ext-xdebug is loaded'); } - $this->setExpectedException('SoapFault'); + $this->expectException(\SoapFault::class); new ClientEncoder(null); } @@ -76,21 +76,4 @@ public function testEncodeRequestForBlzServiceNonWsdlMode() $this->assertEquals($expected, (string)$request->getBody()); } - - 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 4661700d422c10becb08b3f0116845b4abbf88d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Wed, 28 Oct 2020 08:33:37 +0100 Subject: [PATCH 3/3] Do not skip tests when ext-xdebug v2.7 is loaded PHP no longer yields a fatal error when ext-xdebug is loaded and an invalid SOAP parameter is encountered. As of ext-xdebug v2.7, this throws a SoapFault as expected. Refs https://bugs.xdebug.org/bug_view_page.php?bug_id=00001629 --- README.md | 7 ++++--- src/Client.php | 7 ++++--- tests/ClientTest.php | 4 ++-- tests/Protocol/ClientEncoderTest.php | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 73305f0..22afb6d 100644 --- a/README.md +++ b/README.md @@ -147,9 +147,10 @@ try { } ``` -> Note that if you have `ext-xdebug` loaded, this may halt with a fatal - error instead of throwing a `SoapFault`. It is not recommended to use this - extension in production, so this should only ever affect test environments. +> Note that if you have an old version of `ext-xdebug` < 2.7 loaded, this may + halt with a fatal error instead of throwing a `SoapFault`. It is not + recommended to use this extension in production, so this should only ever + affect test environments. The `Client` constructor accepts an array of options. All given options will be passed through to the underlying `SoapClient`. However, not all options diff --git a/src/Client.php b/src/Client.php index d1f91ca..5996e44 100644 --- a/src/Client.php +++ b/src/Client.php @@ -82,9 +82,10 @@ * } * ``` * - * > Note that if you have `ext-xdebug` loaded, this may halt with a fatal - * error instead of throwing a `SoapFault`. It is not recommended to use this - * extension in production, so this should only ever affect test environments. + * > Note that if you have an old version of `ext-xdebug` < 2.7 loaded, this may + * halt with a fatal error instead of throwing a `SoapFault`. It is not + * recommended to use this extension in production, so this should only ever + * affect test environments. * * The `Client` constructor accepts an array of options. All given options will * be passed through to the underlying `SoapClient`. However, not all options diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 895d3ce..41171ba 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -10,8 +10,8 @@ class ClientTest extends TestCase { public function testConstructorThrowsWhenUrlIsInvalid() { - if (extension_loaded('xdebug')) { - $this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug is loaded'); + if (extension_loaded('xdebug') && phpversion('xdebug') < 2.7) { + $this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug < 2.7 is loaded'); } $browser = $this->getMockBuilder('React\Http\Browser')->disableOriginalConstructor()->getMock(); diff --git a/tests/Protocol/ClientEncoderTest.php b/tests/Protocol/ClientEncoderTest.php index cd9dd23..11c3497 100644 --- a/tests/Protocol/ClientEncoderTest.php +++ b/tests/Protocol/ClientEncoderTest.php @@ -38,8 +38,8 @@ public function testEncodeCreatesRequestForNonWsdlRpcFunctionWithSoapV12() public function testConstructorThrowsWhenUrlIsInvalid() { - if (extension_loaded('xdebug')) { - $this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug is loaded'); + if (extension_loaded('xdebug') && phpversion('xdebug') < 2.7) { + $this->markTestSkipped('Invalid WSDL causes a fatal error when ext-xdebug < 2.7 is loaded'); } $this->expectException(\SoapFault::class); @@ -48,8 +48,8 @@ public function testConstructorThrowsWhenUrlIsInvalid() public function testConstructorThrowsWhenNonWsdlDoesNotDefineLocationAndUri() { - if (extension_loaded('xdebug')) { - $this->markTestSkipped('Invalid non-WSDL mode causes a fatal error when ext-xdebug is loaded'); + if (extension_loaded('xdebug') && phpversion('xdebug') < 2.7) { + $this->markTestSkipped('Invalid non-WSDL mode causes a fatal error when ext-xdebug < 2.7 is loaded'); } $this->expectException(\SoapFault::class);