Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ assert('http://example.com/soap/service' == $client->getLocation(0));

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

#### withRequestTarget($requestTarget)

This method allows you to change the destination of your SOAP calls. It returns a new Client instance
with the specified request-target.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this relate to the getLocation() method (and its name)?

This could also use some tests I suppose :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can rename to setLocation, but thought this may be confusing because getLocation and setLocation are not really getters / setter for the same thing.

This PR adds tests in tests/FunctionalTest.php.


### Proxy

The `Proxy` class wraps an existing [`Client`](#client) instance in order to ease calling
Expand Down
8 changes: 8 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ public function getLocation($function)
// encode request for given $function
return (string)$this->encoder->encode($function, array())->getUri();
}

public function withRequestTarget($requestTarget)
{
$copy = clone $this;
$copy->encoder = $this->encoder->withRequestTarget($requestTarget);

return $copy;
}
}
16 changes: 14 additions & 2 deletions src/Protocol/ClientEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

class ClientEncoder extends SoapClient
{
private $request = null;
private $request = null;
private $requestTarget = null;

public function encode($name, $args)
{
Expand All @@ -21,9 +22,12 @@ public function encode($name, $args)

public function __doRequest($request, $location, $action, $version, $one_way = 0)
{

$requestTarget = $this->requestTarget !== null ? $this->requestTarget : $location;

$this->request = new Request(
'POST',
(string)$location,
(string)$requestTarget,
array(
'SOAPAction' => (string)$action,
'Content-Type' => 'text/xml; charset=utf-8',
Expand All @@ -35,4 +39,12 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0
// do not actually block here, just pretend we're done...
return '';
}

public function withRequestTarget($requestTarget)
{
$copy = clone $this;
$copy->requestTarget = $requestTarget;

return $copy;
}
}
23 changes: 23 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,27 @@ public function testGetLocationForUnknownFunctionNumberFails()
{
$this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation(100));
}

public function testWrongRequestTarget()
{
$api = new Proxy($this->client->withRequestTarget('nonsense.not.existing'));

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

$this->expectException('Exception');
Block\await($promise, $this->loop);
}

public function testCorrectRequestTarget()
{
$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);
}
}