From 5ab82360c74edabef598f972417c6e16a8f8d941 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 17 Aug 2012 11:48:41 -0500 Subject: [PATCH 1/3] Fixed issue with soap faults - Basically, calling $soapServer->fault() causes the script to end -- see https://bugs.php.net/bug.php?id=49513 - Workaround is to manually instantiate the SoapFault, and set that as the response. When you echo it, it will send headers and the payload. This makes it testable. --- src/Server.php | 12 ++++++++---- test/ServerTest.php | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Server.php b/src/Server.php index 05f0bb71..347e8aa9 100644 --- a/src/Server.php +++ b/src/Server.php @@ -798,16 +798,16 @@ public function handle($request = null) $soap = $this->_getSoap(); + $fault = false; ob_start(); if ($setRequestException instanceof \Exception) { - // Send SOAP fault message if we've catched exception - $soap->fault('Sender', $setRequestException->getMessage()); + // Create SOAP fault message if we've caught a request exception + $fault = $this->fault($setRequestException->getMessage(), 'Sender'); } else { try { $soap->handle($this->request); } catch (\Exception $e) { $fault = $this->fault($e); - $soap->fault($fault->faultcode, $fault->faultstring); } } $this->response = ob_get_clean(); @@ -816,8 +816,12 @@ public function handle($request = null) restore_error_handler(); ini_set('display_errors', $displayErrorsOriginalState); + // Send a fault, if we have one + if ($fault) { + $this->response = $fault; + } + if (!$this->returnResponse) { - echo $this->response; return; } diff --git a/test/ServerTest.php b/test/ServerTest.php index f614ca7c..3b8796fe 100644 --- a/test/ServerTest.php +++ b/test/ServerTest.php @@ -858,6 +858,9 @@ public function testHandleUsesProperRequestParameter() $this->assertTrue(is_string($server->mockSoapServer->handle[0])); } + /** + * @runInSeparateProcess + */ public function testShouldThrowExceptionIfHandledRequestContainsDoctype() { $server = new Server(); @@ -881,7 +884,7 @@ public function testShouldThrowExceptionIfHandledRequestContainsDoctype() . '' . '' . "\n"; $response = $server->handle($request); - $this->assertContains($response, 'Invalid XML'); + $this->assertContains('Invalid XML', $response->getMessage()); } } From 7c38895b4fff8cf3ff4c396a656bd41255339523 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 17 Aug 2012 12:16:48 -0500 Subject: [PATCH 2/3] Pull response from server if output buffer is empty - Ensures that methods not outputting content can still have responses aggregated --- src/Client/Local.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Client/Local.php b/src/Client/Local.php index c482d067..380ddf66 100644 --- a/src/Client/Local.php +++ b/src/Client/Local.php @@ -70,6 +70,13 @@ public function _doRequest(Common $client, $request, $location, $action, $versio $this->server->handle($request); $response = ob_get_clean(); + if ($response === null || $response === '') { + $serverResponse = $this->server->getResponse(); + if ($serverResponse !== null) { + $response = $serverResponse; + } + } + return $response; } } From 073ffb172f17237f3ff44a6b1c7c2ad5290cc8a3 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 17 Aug 2012 12:56:06 -0500 Subject: [PATCH 3/3] When returnResponse is false, echo the response --- src/Server.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Server.php b/src/Server.php index 347e8aa9..8a609a1b 100644 --- a/src/Server.php +++ b/src/Server.php @@ -822,6 +822,7 @@ public function handle($request = null) } if (!$this->returnResponse) { + echo $this->response; return; }