Skip to content

Commit 340426a

Browse files
Renamed withTarget to withRequestTarget, fixed unit tests and code style.
1 parent 063dc25 commit 340426a

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ assert('http://example.com/soap/service' == $client->getLocation(0));
166166

167167
Passing a `$function` not defined in the WSDL file will throw a `SoapFault`.
168168

169-
#### withTarget($newTarget)
169+
#### withRequestTarget($requestTarget)
170170

171-
This method allows you to change the destination of your SOAP calls. It does not change the Client object, but returns a new
172-
Client with the overriden target.
171+
This method allows you to change the destination of your SOAP calls. It returns a new Client instance
172+
with the specified request-target.
173173

174174
### Proxy
175175

src/Client.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function soapCall($name, $args)
5050

5151
public function handleResponse(ResponseInterface $response)
5252
{
53-
return $this->decoder->decode((string) $response->getBody());
53+
return $this->decoder->decode((string)$response->getBody());
5454
}
5555

5656
public function handleError(Exception $error)
@@ -103,10 +103,11 @@ public function getLocation($function)
103103
return (string)$this->encoder->encode($function, array())->getUri();
104104
}
105105

106-
public function withTarget($target)
106+
public function withRequestTarget($requestTarget)
107107
{
108108
$copy = clone $this;
109-
$copy->encoder = $this->encoder->withTarget($target);
109+
$copy->encoder = $this->encoder->withRequestTarget($requestTarget);
110+
110111
return $copy;
111112
}
112113
}

src/Protocol/ClientEncoder.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
class ClientEncoder extends SoapClient
99
{
10-
private $request = null;
11-
private $targetOverride = null;
10+
private $request = null;
11+
private $requestTarget = null;
1212

1313
public function encode($name, $args)
1414
{
@@ -23,27 +23,28 @@ public function encode($name, $args)
2323
public function __doRequest($request, $location, $action, $version, $one_way = 0)
2424
{
2525

26-
$finalLocation = $this->targetOverride !== null ? $this->targetOverride : $location;
26+
$requestTarget = $this->requestTarget !== null ? $this->requestTarget : $location;
2727

2828
$this->request = new Request(
2929
'POST',
30-
(string) $finalLocation,
31-
new Headers(array(
32-
'SOAPAction' => (string) $action,
30+
(string)$requestTarget,
31+
array(
32+
'SOAPAction' => (string)$action,
3333
'Content-Type' => 'text/xml; charset=utf-8',
3434
'Content-Length' => strlen($request)
35-
)),
36-
new Body((string) $request)
35+
),
36+
(string)$request
3737
);
3838

3939
// do not actually block here, just pretend we're done...
4040
return '';
4141
}
4242

43-
public function withTarget($newTarget)
43+
public function withRequestTarget($requestTarget)
4444
{
4545
$copy = clone $this;
46-
$copy->targetOverride = $newTarget;
46+
$copy->requestTarget = $requestTarget;
47+
4748
return $copy;
4849
}
4950
}

tests/FunctionalTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,26 @@ public function testGetLocationForUnknownFunctionNumberFails()
8989
$this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100));
9090
}
9191

92-
public function testWrongLocationOverride()
92+
public function testWrongRequestTarget()
9393
{
94-
$api = new Proxy($this->client->withTarget('nonsense.not.existing'));
94+
$api = new Proxy($this->client->withRequestTarget('nonsense.not.existing'));
9595

9696
$promise = $api->getBank(array('blz' => '12070000'));
9797

98-
$this->expectPromiseReject($promise);
99-
100-
$this->setExpectedException('Exception');
98+
$this->expectException('Exception');
10199
Block\await($promise, $this->loop);
102100
}
103101

104-
public function testCorrectLocationOverride()
102+
public function testCorrectRequestTarget()
105103
{
106-
$this->client->withTarget('nonsense.not.existing');
107-
$this->client->withTarget('http://www.thomas-bayer.com/axis2/services/BLZService');
108-
$this->testBlzService();
104+
$client = $this->client->withRequestTarget('nonsense.not.existing');
105+
$client = $client->withRequestTarget('http://www.thomas-bayer.com/axis2/services/BLZService');
106+
$api = new Proxy($client);
107+
108+
$promise = $api->getBank(array('blz' => '12070000'));
109+
110+
$result = Block\await($promise, $this->loop);
111+
112+
$this->assertInternalType('object', $result);
109113
}
110114
}

0 commit comments

Comments
 (0)