diff --git a/src/Client.php b/src/Client.php index e085ee3..6e57ecf 100644 --- a/src/Client.php +++ b/src/Client.php @@ -156,6 +156,16 @@ public function __construct(Browser $browser, $wsdlContents, array $options = ar { $wsdl = $wsdlContents !== null ? 'data://text/plain;base64,' . base64_encode($wsdlContents) : null; + // Accept HTTP responses with error status codes as valid responses. + // This is done in order to process these error responses through the normal SOAP decoder. + // Additionally, we explicitly limit number of redirects to zero because following redirects makes little sense + // because it transforms the POST request to a GET one and hence loses the SOAP request body. + $browser = $browser->withOptions(array( + 'obeySuccessCode' => false, + 'followRedirects' => true, + 'maxRedirects' => 0 + )); + $this->browser = $browser; $this->encoder = new ClientEncoder($wsdl, $options); $this->decoder = new ClientDecoder($wsdl, $options); @@ -200,7 +210,6 @@ function (ResponseInterface $response) use ($decoder, $name) { ); } - /** * Returns an array of functions defined in the WSDL. * diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 2572cfe..160fe9e 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -45,6 +45,7 @@ public function testNonWsdlClientSendsPostRequestToGivenLocationForAnySoapCall() }; $promise = new Promise(function () { }); $browser = $this->getMockBuilder('Clue\React\Buzz\Browser')->disableOriginalConstructor()->getMock(); + $browser->expects($this->once())->method('withOptions')->willReturnSelf(); $browser->expects($this->once())->method('send')->with($this->callback($verify))->willReturn($promise); $client = new Client($browser, null, array('location' => 'http://example.com', 'uri' => 'http://example.com/uri')); diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 9093088..f694edb 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -117,9 +117,27 @@ public function testBlzServiceNonWsdlModeReturnedWithoutOuterResultStructure() } /** - * @expectedException Exception + * @expectedException RuntimeException + * @expectedExeptionMessage redirects */ - public function testBlzServiceWithInvalidBlz() + 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'), + 'uri' => 'http://thomas-bayer.com/blz/', + )); + + $api = new Proxy($this->client); + $promise = $api->getBank('a'); + + $result = Block\await($promise, $this->loop); + } + + /** + * @expectedException SoapFault + * @expectedExeptionMessage Keine Bank zur BLZ invalid gefunden! + */ + public function testBlzServiceWithInvalidBlzRejectsWithSoapFault() { $api = new Proxy($this->client); @@ -129,13 +147,14 @@ public function testBlzServiceWithInvalidBlz() } /** - * @expectedException Exception + * @expectedException SoapFault + * @expectedExceptionMessage Function ("doesNotExist") is not a valid method for this service */ - public function testBlzServiceWithInvalidMethod() + public function testBlzServiceWithInvalidMethodRejectsWithSoapFault() { $api = new Proxy($this->client); - $promise = $api->doesNotexist(); + $promise = $api->doesNotExist(); Block\await($promise, $this->loop); }