From 03786027deb2a85c863daa43ee294ddb2baecc29 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 15:15:23 +0200 Subject: [PATCH 01/12] Added the possibility to override the webservice location to allow one to load the WSDL from one place and to query a server that is different from the one specified in the WSDL --- src/Client.php | 7 +++++++ src/Protocol/ClientEncoder.php | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index d112772..4701687 100644 --- a/src/Client.php +++ b/src/Client.php @@ -102,4 +102,11 @@ public function getLocation($function) // encode request for given $function return (string)$this->encoder->encode($function, array())->getUri(); } + + public function overrideLocation($location) + { + $copy = clone $this; + $copy->encoder = $this->encoder->overrideLocation($location); + return $copy; + } } diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index e84a0d2..3932df7 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -7,7 +7,8 @@ class ClientEncoder extends SoapClient { - private $request = null; + private $request = null; + private $locationOverride = null; public function encode($name, $args) { @@ -21,9 +22,11 @@ public function encode($name, $args) public function __doRequest($request, $location, $action, $version, $one_way = 0) { + $finalLocation = $this->locationOverride !== null ? $this->locationOverride : $location; + $this->request = new Request( 'POST', - (string)$location, + (string)$finalLocation, array( 'SOAPAction' => (string)$action, 'Content-Type' => 'text/xml; charset=utf-8', @@ -35,4 +38,11 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0 // do not actually block here, just pretend we're done... return ''; } + + public function overrideLocation($newLocation) + { + $copy = clone $this; + $this->locationOverride = $newLocation; + return $copy; + } } From dbc77f1dd4a0409379141a98466eee01684387be Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 16:21:06 +0200 Subject: [PATCH 02/12] - Introduced PHP Unit as a development composer dependency - Added tests for the location override feature --- tests/FunctionalTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index bd101eb..7978d0d 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -88,4 +88,24 @@ public function testGetLocationForUnknownFunctionNumberFails() { $this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100)); } + + public function testWrongLocationOverride() + { + $this->client->overrideLocation('nonsense.not.existing'); + $api = new Proxy($this->client); + + $promise = $api->getBank(array('blz' => '12070000')); + + $this->expectPromiseReject($promise); + + $this->setExpectedException('Exception'); + $this->waitForPromise($promise, $this->loop); + } + + public function testCorrectLocationOverride() + { + $this->client->overrideLocation('nonsense.not.existing'); + $this->client->overrideLocation('http://www.thomas-bayer.com/axis2/services/BLZService'); + $this->testBlzService(); + } } From 2227e8e098510a6e4c3c3031ffcbfcefd713a00c Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 17:12:28 +0200 Subject: [PATCH 03/12] - Documentation/better naming for the location getter/override. - Test for the location getter --- README.md | 8 +++++ src/Client.php | 9 +++-- src/Protocol/ClientEncoder.php | 62 +++++++++++++++++++++++++--------- tests/FunctionalTest.php | 14 ++++++-- 4 files changed, 72 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index eca4e0c..439e0cc 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,14 @@ assert('http://example.com/soap/service' == $client->getLocation(0)); Passing a `$function` not defined in the WSDL file will throw a `SoapFault`. +#### overrideTarget($newTarget) + +This method allows you to change the destination of your SOAP calls. + +#### getWsdlTarget() + +This method allows you to retrieve the target URL specified in the WSDL file. + ### Proxy The `Proxy` class wraps an existing [`Client`](#client) instance in order to ease calling diff --git a/src/Client.php b/src/Client.php index 4701687..6863599 100644 --- a/src/Client.php +++ b/src/Client.php @@ -103,10 +103,15 @@ public function getLocation($function) return (string)$this->encoder->encode($function, array())->getUri(); } - public function overrideLocation($location) + public function overrideTarget($target) { $copy = clone $this; - $copy->encoder = $this->encoder->overrideLocation($location); + $copy->encoder = $this->encoder->overrideTarget($target); return $copy; } + + public function getWsdlTarget() + { + return $this->encoder->getWsdlTarget(); + } } diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 3932df7..bb89f7f 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -7,8 +7,10 @@ class ClientEncoder extends SoapClient { - private $request = null; - private $locationOverride = null; + private $request = null; + private $targetOverride = null; + private $target = null; + private $findTarget = false; public function encode($name, $args) { @@ -22,27 +24,55 @@ public function encode($name, $args) public function __doRequest($request, $location, $action, $version, $one_way = 0) { - $finalLocation = $this->locationOverride !== null ? $this->locationOverride : $location; - - $this->request = new Request( - 'POST', - (string)$finalLocation, - array( - 'SOAPAction' => (string)$action, - 'Content-Type' => 'text/xml; charset=utf-8', - 'Content-Length' => strlen($request) - ), - (string)$request - ); + + if ($this->findTarget) { + $this->target = $location; + $this->findTarget = false; + } else { + $finalLocation = $this->targetOverride !== null ? $this->targetOverride : $location; + + $this->request = new Request( + 'POST', + (string) $finalLocation, + new Headers(array( + 'SOAPAction' => (string) $action, + 'Content-Type' => 'text/xml; charset=utf-8', + 'Content-Length' => strlen($request) + )), + new Body((string) $request) + ); + } // do not actually block here, just pretend we're done... return ''; } - public function overrideLocation($newLocation) + public function overrideTarget($newTarget) { $copy = clone $this; - $this->locationOverride = $newLocation; + $this->targetOverride = $newTarget; return $copy; } + + public function getWsdlTarget() + { + /* + * We can't just use a function with an empty name. + * SoapClient complains if the request does not exist. + */ + $functionDescriptions = $this->__getFunctions(); + $functionDescription = $functionDescriptions[0]; /* PHP 5.3 support. */ + $spaceIndex = strpos($functionDescription, ' '); + $openingParenIndex = strpos($functionDescription, '('); + $function = substr( + $functionDescription, + $spaceIndex + 1, + $openingParenIndex - $spaceIndex - 1 + ); + + $this->findTarget = true; + $this->__soapCall($function, []); + return $this->target; + } + } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 7978d0d..013963b 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -91,7 +91,7 @@ public function testGetLocationForUnknownFunctionNumberFails() public function testWrongLocationOverride() { - $this->client->overrideLocation('nonsense.not.existing'); + $this->client->overrideTarget('nonsense.not.existing'); $api = new Proxy($this->client); $promise = $api->getBank(array('blz' => '12070000')); @@ -104,8 +104,16 @@ public function testWrongLocationOverride() public function testCorrectLocationOverride() { - $this->client->overrideLocation('nonsense.not.existing'); - $this->client->overrideLocation('http://www.thomas-bayer.com/axis2/services/BLZService'); + $this->client->overrideTarget('nonsense.not.existing'); + $this->client->overrideTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); $this->testBlzService(); } + + public function testGetLocation() + { + $this->assertEquals( + $this->client->getWsdlTarget(), + 'http://www.thomas-bayer.com/axis2/services/BLZService' + ); + } } From 0d62b56f4398561f66e102953c90c34fcca817f6 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 17:16:39 +0200 Subject: [PATCH 04/12] - Removed the dependency to PHPUnit in composer.json - Renamed overrideTarget to withOverridenTarget() everywhere --- README.md | 5 +++-- src/Client.php | 4 ++-- src/Protocol/ClientEncoder.php | 2 +- tests/FunctionalTest.php | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 439e0cc..bd335bd 100644 --- a/README.md +++ b/README.md @@ -166,9 +166,10 @@ assert('http://example.com/soap/service' == $client->getLocation(0)); Passing a `$function` not defined in the WSDL file will throw a `SoapFault`. -#### overrideTarget($newTarget) +#### withOverridenTarget($newTarget) -This method allows you to change the destination of your SOAP calls. +This method allows you to change the destination of your SOAP calls. It does not change the Client object, but returns a new +Client with the overriden target. #### getWsdlTarget() diff --git a/src/Client.php b/src/Client.php index 6863599..19ca786 100644 --- a/src/Client.php +++ b/src/Client.php @@ -103,10 +103,10 @@ public function getLocation($function) return (string)$this->encoder->encode($function, array())->getUri(); } - public function overrideTarget($target) + public function withOverridenTarget($target) { $copy = clone $this; - $copy->encoder = $this->encoder->overrideTarget($target); + $copy->encoder = $this->encoder->withOverridenTarget($target); return $copy; } diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index bb89f7f..e051bba 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -47,7 +47,7 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0 return ''; } - public function overrideTarget($newTarget) + public function withOverridenTarget($newTarget) { $copy = clone $this; $this->targetOverride = $newTarget; diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 013963b..4a34589 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -91,7 +91,7 @@ public function testGetLocationForUnknownFunctionNumberFails() public function testWrongLocationOverride() { - $this->client->overrideTarget('nonsense.not.existing'); + $this->client->withOverridenTarget('nonsense.not.existing'); $api = new Proxy($this->client); $promise = $api->getBank(array('blz' => '12070000')); @@ -104,8 +104,8 @@ public function testWrongLocationOverride() public function testCorrectLocationOverride() { - $this->client->overrideTarget('nonsense.not.existing'); - $this->client->overrideTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); + $this->client->withOverridenTarget('nonsense.not.existing'); + $this->client->withOverridenTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); $this->testBlzService(); } From a85eeaca5e7b1fbcceebfd72d87f0cd8d7d61678 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 17:30:30 +0200 Subject: [PATCH 05/12] Renamed withOverridenTarget() to withTarget() everywhere --- README.md | 2 +- src/Client.php | 4 ++-- src/Protocol/ClientEncoder.php | 2 +- tests/FunctionalTest.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bd335bd..1268461 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ assert('http://example.com/soap/service' == $client->getLocation(0)); Passing a `$function` not defined in the WSDL file will throw a `SoapFault`. -#### withOverridenTarget($newTarget) +#### withTarget($newTarget) This method allows you to change the destination of your SOAP calls. It does not change the Client object, but returns a new Client with the overriden target. diff --git a/src/Client.php b/src/Client.php index 19ca786..0cfbb55 100644 --- a/src/Client.php +++ b/src/Client.php @@ -103,10 +103,10 @@ public function getLocation($function) return (string)$this->encoder->encode($function, array())->getUri(); } - public function withOverridenTarget($target) + public function withTarget($target) { $copy = clone $this; - $copy->encoder = $this->encoder->withOverridenTarget($target); + $copy->encoder = $this->encoder->withTarget($target); return $copy; } diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index e051bba..1f0a9b7 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -47,7 +47,7 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0 return ''; } - public function withOverridenTarget($newTarget) + public function withTarget($newTarget) { $copy = clone $this; $this->targetOverride = $newTarget; diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 4a34589..db601d4 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -91,7 +91,7 @@ public function testGetLocationForUnknownFunctionNumberFails() public function testWrongLocationOverride() { - $this->client->withOverridenTarget('nonsense.not.existing'); + $this->client->withTarget('nonsense.not.existing'); $api = new Proxy($this->client); $promise = $api->getBank(array('blz' => '12070000')); @@ -104,8 +104,8 @@ public function testWrongLocationOverride() public function testCorrectLocationOverride() { - $this->client->withOverridenTarget('nonsense.not.existing'); - $this->client->withOverridenTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); + $this->client->withTarget('nonsense.not.existing'); + $this->client->withTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); $this->testBlzService(); } From f47c93c10873b4efb42cd80f2f804a7681a830e3 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 17:33:56 +0200 Subject: [PATCH 06/12] Replaced one instance of shorthand array syntax use with a plain old array() call --- src/Protocol/ClientEncoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 1f0a9b7..3fffb7d 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -71,7 +71,7 @@ public function getWsdlTarget() ); $this->findTarget = true; - $this->__soapCall($function, []); + $this->__soapCall($function, array()); return $this->target; } From 425f0c7c793a608b24bb6ae4f1198d0b07c8526f Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 18:29:33 +0200 Subject: [PATCH 07/12] Made a copy of the location before assigning it because __doRequest was passed a reference --- src/Protocol/ClientEncoder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 3fffb7d..7af8da0 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -26,7 +26,7 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0 { if ($this->findTarget) { - $this->target = $location; + $this->target = (string) $location; $this->findTarget = false; } else { $finalLocation = $this->targetOverride !== null ? $this->targetOverride : $location; @@ -71,7 +71,7 @@ public function getWsdlTarget() ); $this->findTarget = true; - $this->__soapCall($function, array()); + $this->__soapCall($function, []); return $this->target; } From 91748fc5b75811812d1b9c76c671250866ab0e72 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Thu, 3 Sep 2015 18:32:49 +0200 Subject: [PATCH 08/12] Replaced one instance of shorthand array syntax use with a plain old array() call --- src/Protocol/ClientEncoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 7af8da0..659de67 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -71,7 +71,7 @@ public function getWsdlTarget() ); $this->findTarget = true; - $this->__soapCall($function, []); + $this->__soapCall($function, array()); return $this->target; } From 858c2951054004bb8be403617453b16cd8d31d7b Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Fri, 4 Sep 2015 17:29:56 +0200 Subject: [PATCH 09/12] Overwriting the target of the copy instead of the original ClientEncoder --- src/Protocol/ClientEncoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 659de67..1c17317 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -50,7 +50,7 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0 public function withTarget($newTarget) { $copy = clone $this; - $this->targetOverride = $newTarget; + $copy->targetOverride = $newTarget; return $copy; } From d2e13e2c960f467b1f126819ea839c2305b32c40 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Sat, 19 Sep 2015 12:42:04 +0200 Subject: [PATCH 10/12] Removed features that don't belong in that pull request --- README.md | 4 --- src/Client.php | 7 +---- src/Protocol/ClientEncoder.php | 53 ++++++++-------------------------- tests/FunctionalTest.php | 11 +------ 4 files changed, 14 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 1268461..b828c48 100644 --- a/README.md +++ b/README.md @@ -171,10 +171,6 @@ Passing a `$function` not defined in the WSDL file will throw a `SoapFault`. This method allows you to change the destination of your SOAP calls. It does not change the Client object, but returns a new Client with the overriden target. -#### getWsdlTarget() - -This method allows you to retrieve the target URL specified in the WSDL file. - ### Proxy The `Proxy` class wraps an existing [`Client`](#client) instance in order to ease calling diff --git a/src/Client.php b/src/Client.php index 0cfbb55..97e5ed4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -50,7 +50,7 @@ public function soapCall($name, $args) public function handleResponse(ResponseInterface $response) { - return $this->decoder->decode((string)$response->getBody()); + return $this->decoder->decode((string) $response->getBody()); } public function handleError(Exception $error) @@ -109,9 +109,4 @@ public function withTarget($target) $copy->encoder = $this->encoder->withTarget($target); return $copy; } - - public function getWsdlTarget() - { - return $this->encoder->getWsdlTarget(); - } } diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 1c17317..79b7855 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -9,8 +9,6 @@ class ClientEncoder extends SoapClient { private $request = null; private $targetOverride = null; - private $target = null; - private $findTarget = false; public function encode($name, $args) { @@ -25,23 +23,18 @@ public function encode($name, $args) public function __doRequest($request, $location, $action, $version, $one_way = 0) { - if ($this->findTarget) { - $this->target = (string) $location; - $this->findTarget = false; - } else { - $finalLocation = $this->targetOverride !== null ? $this->targetOverride : $location; - - $this->request = new Request( - 'POST', - (string) $finalLocation, - new Headers(array( - 'SOAPAction' => (string) $action, - 'Content-Type' => 'text/xml; charset=utf-8', - 'Content-Length' => strlen($request) - )), - new Body((string) $request) - ); - } + $finalLocation = $this->targetOverride !== null ? $this->targetOverride : $location; + + $this->request = new Request( + 'POST', + (string) $finalLocation, + new Headers(array( + 'SOAPAction' => (string) $action, + 'Content-Type' => 'text/xml; charset=utf-8', + 'Content-Length' => strlen($request) + )), + new Body((string) $request) + ); // do not actually block here, just pretend we're done... return ''; @@ -53,26 +46,4 @@ public function withTarget($newTarget) $copy->targetOverride = $newTarget; return $copy; } - - public function getWsdlTarget() - { - /* - * We can't just use a function with an empty name. - * SoapClient complains if the request does not exist. - */ - $functionDescriptions = $this->__getFunctions(); - $functionDescription = $functionDescriptions[0]; /* PHP 5.3 support. */ - $spaceIndex = strpos($functionDescription, ' '); - $openingParenIndex = strpos($functionDescription, '('); - $function = substr( - $functionDescription, - $spaceIndex + 1, - $openingParenIndex - $spaceIndex - 1 - ); - - $this->findTarget = true; - $this->__soapCall($function, array()); - return $this->target; - } - } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index db601d4..71946e4 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -91,8 +91,7 @@ public function testGetLocationForUnknownFunctionNumberFails() public function testWrongLocationOverride() { - $this->client->withTarget('nonsense.not.existing'); - $api = new Proxy($this->client); + $api = new Proxy($this->client->withTarget('nonsense.not.existing')); $promise = $api->getBank(array('blz' => '12070000')); @@ -108,12 +107,4 @@ public function testCorrectLocationOverride() $this->client->withTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); $this->testBlzService(); } - - public function testGetLocation() - { - $this->assertEquals( - $this->client->getWsdlTarget(), - 'http://www.thomas-bayer.com/axis2/services/BLZService' - ); - } } From 063dc2566dc48a6d41cd3c9daac5ecdf001a4108 Mon Sep 17 00:00:00 2001 From: Florian Simon Date: Wed, 16 Mar 2016 08:34:51 +0100 Subject: [PATCH 11/12] Fixes tests --- tests/FunctionalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 71946e4..2ae2439 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -98,7 +98,7 @@ public function testWrongLocationOverride() $this->expectPromiseReject($promise); $this->setExpectedException('Exception'); - $this->waitForPromise($promise, $this->loop); + Block\await($promise, $this->loop); } public function testCorrectLocationOverride() From 340426a3307b419de1fc9867b4bbe22ef949ff19 Mon Sep 17 00:00:00 2001 From: Pascal Hofmann Date: Tue, 7 Nov 2017 14:37:20 +0100 Subject: [PATCH 12/12] Renamed withTarget to withRequestTarget, fixed unit tests and code style. --- README.md | 6 +++--- src/Client.php | 7 ++++--- src/Protocol/ClientEncoder.php | 21 +++++++++++---------- tests/FunctionalTest.php | 22 +++++++++++++--------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b828c48..00d16e4 100644 --- a/README.md +++ b/README.md @@ -166,10 +166,10 @@ assert('http://example.com/soap/service' == $client->getLocation(0)); Passing a `$function` not defined in the WSDL file will throw a `SoapFault`. -#### withTarget($newTarget) +#### withRequestTarget($requestTarget) -This method allows you to change the destination of your SOAP calls. It does not change the Client object, but returns a new -Client with the overriden target. +This method allows you to change the destination of your SOAP calls. It returns a new Client instance +with the specified request-target. ### Proxy diff --git a/src/Client.php b/src/Client.php index 97e5ed4..542b93c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -50,7 +50,7 @@ public function soapCall($name, $args) public function handleResponse(ResponseInterface $response) { - return $this->decoder->decode((string) $response->getBody()); + return $this->decoder->decode((string)$response->getBody()); } public function handleError(Exception $error) @@ -103,10 +103,11 @@ public function getLocation($function) return (string)$this->encoder->encode($function, array())->getUri(); } - public function withTarget($target) + public function withRequestTarget($requestTarget) { $copy = clone $this; - $copy->encoder = $this->encoder->withTarget($target); + $copy->encoder = $this->encoder->withRequestTarget($requestTarget); + return $copy; } } diff --git a/src/Protocol/ClientEncoder.php b/src/Protocol/ClientEncoder.php index 79b7855..65bb565 100644 --- a/src/Protocol/ClientEncoder.php +++ b/src/Protocol/ClientEncoder.php @@ -7,8 +7,8 @@ class ClientEncoder extends SoapClient { - private $request = null; - private $targetOverride = null; + private $request = null; + private $requestTarget = null; public function encode($name, $args) { @@ -23,27 +23,28 @@ public function encode($name, $args) public function __doRequest($request, $location, $action, $version, $one_way = 0) { - $finalLocation = $this->targetOverride !== null ? $this->targetOverride : $location; + $requestTarget = $this->requestTarget !== null ? $this->requestTarget : $location; $this->request = new Request( 'POST', - (string) $finalLocation, - new Headers(array( - 'SOAPAction' => (string) $action, + (string)$requestTarget, + array( + 'SOAPAction' => (string)$action, 'Content-Type' => 'text/xml; charset=utf-8', 'Content-Length' => strlen($request) - )), - new Body((string) $request) + ), + (string)$request ); // do not actually block here, just pretend we're done... return ''; } - public function withTarget($newTarget) + public function withRequestTarget($requestTarget) { $copy = clone $this; - $copy->targetOverride = $newTarget; + $copy->requestTarget = $requestTarget; + return $copy; } } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 2ae2439..2d657f8 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -89,22 +89,26 @@ public function testGetLocationForUnknownFunctionNumberFails() $this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100)); } - public function testWrongLocationOverride() + public function testWrongRequestTarget() { - $api = new Proxy($this->client->withTarget('nonsense.not.existing')); + $api = new Proxy($this->client->withRequestTarget('nonsense.not.existing')); $promise = $api->getBank(array('blz' => '12070000')); - $this->expectPromiseReject($promise); - - $this->setExpectedException('Exception'); + $this->expectException('Exception'); Block\await($promise, $this->loop); } - public function testCorrectLocationOverride() + public function testCorrectRequestTarget() { - $this->client->withTarget('nonsense.not.existing'); - $this->client->withTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); - $this->testBlzService(); + $client = $this->client->withRequestTarget('nonsense.not.existing'); + $client = $client->withRequestTarget('http://www.thomas-bayer.com/axis2/services/BLZService'); + $api = new Proxy($client); + + $promise = $api->getBank(array('blz' => '12070000')); + + $result = Block\await($promise, $this->loop); + + $this->assertInternalType('object', $result); } }