Skip to content

Commit ec37e8b

Browse files
committed
[SoapClient] Fixes __getLastRequest and __getLastResponce
1 parent 61f6a97 commit ec37e8b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/VCR/Util/SoapClient.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class SoapClient extends \SoapClient
1717

1818
protected $options = array();
1919

20+
protected $response;
21+
22+
protected $request;
23+
2024
public function __construct($wsdl, $options = array()) {
2125
$this->options = $options;
2226
parent::__construct($wsdl, $options);
@@ -37,6 +41,8 @@ public function __construct($wsdl, $options = array()) {
3741
*/
3842
public function __doRequest($request, $location, $action, $version, $one_way = 0)
3943
{
44+
$this->request = $request;
45+
4046
$soapHook = $this->getLibraryHook();
4147

4248
if ($soapHook->isEnabled()) {
@@ -45,9 +51,21 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0
4551
$response = $this->realDoRequest($request, $location, $action, $version, $one_way);
4652
}
4753

54+
$this->response = $response;
55+
4856
return $one_way ? null : $response;
4957
}
5058

59+
public function __getLastRequest()
60+
{
61+
return $this->request;
62+
}
63+
64+
public function __getLastResponse()
65+
{
66+
return $this->response;
67+
}
68+
5169
/**
5270
* Sets the SOAP library hook which is used to intercept SOAP requests.
5371
*

tests/VCR/Util/SoapClientTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,29 @@ public function testLibraryHook()
139139

140140
$this->assertInstanceOf('\VCR\LibraryHooks\SoapHook', $client->getLibraryHook());
141141
}
142+
143+
public function testGetLastWhateverBeforeRequest()
144+
{
145+
$client = new SoapClient(self::WSDL);
146+
147+
$this->assertNull($client->__getLastRequest());
148+
$this->assertNull($client->__getLastResponse());
149+
}
150+
151+
public function testGetLastWhateverAfterRequest()
152+
{
153+
$request = 'Knorx ist groß';
154+
$response = 'some value';
155+
156+
$hook = $this->getLibraryHookMock(true);
157+
$hook->expects($this->once())->method('doRequest')->will($this->returnValue($response));
158+
159+
$client = new SoapClient(self::WSDL);
160+
$client->setLibraryHook($hook);
161+
162+
$client->__doRequest($request, self::WSDL, self::ACTION, SOAP_1_2, 0);
163+
164+
$this->assertEquals($request, $client->__getLastRequest());
165+
$this->assertEquals($response, $client->__getLastResponse());
166+
}
142167
}

0 commit comments

Comments
 (0)