Skip to content

Commit 1145bcf

Browse files
committed
Merge pull request php-vcr#146 from laland/master
[SoapClient] Fixes __getLastRequest and __getLastResponse
2 parents 31d4f07 + 49c0d3a commit 1145bcf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/VCR/Util/SoapClient.php

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

1818
protected $options = array();
1919

20+
/**
21+
* @var string
22+
*/
23+
protected $response;
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $request;
29+
2030
public function __construct($wsdl, $options = array()) {
2131
$this->options = $options;
2232
parent::__construct($wsdl, $options);
@@ -37,6 +47,8 @@ public function __construct($wsdl, $options = array()) {
3747
*/
3848
public function __doRequest($request, $location, $action, $version, $one_way = 0)
3949
{
50+
$this->request = $request;
51+
4052
$soapHook = $this->getLibraryHook();
4153

4254
if ($soapHook->isEnabled()) {
@@ -45,9 +57,27 @@ public function __doRequest($request, $location, $action, $version, $one_way = 0
4557
$response = $this->realDoRequest($request, $location, $action, $version, $one_way);
4658
}
4759

60+
$this->response = $response;
61+
4862
return $one_way ? null : $response;
4963
}
5064

65+
/**
66+
* @inheritdoc
67+
*/
68+
public function __getLastRequest()
69+
{
70+
return $this->request;
71+
}
72+
73+
/**
74+
* @inheritdoc
75+
*/
76+
public function __getLastResponse()
77+
{
78+
return $this->response;
79+
}
80+
5181
/**
5282
* Sets the SOAP library hook which is used to intercept SOAP requests.
5383
*

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)