Skip to content

Commit 61f6a97

Browse files
committed
Merge pull request php-vcr#141 from laland/master
adds SOAPAction header for soap 1.1
2 parents 1c6aec9 + 18b313e commit 61f6a97

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/VCR/LibraryHooks/SoapHook.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ public function doRequest($request, $location, $action, $version, $one_way = 0,
6969
}
7070

7171
$vcrRequest = new Request('POST', $location);
72-
$contentType = ($version == SOAP_1_2) ? 'application/soap+xml' : 'text/xml';
73-
$vcrRequest->setHeader('Content-Type', $contentType . '; charset=utf-8; action="' . $action . '"');
72+
73+
if ($version === SOAP_1_1) {
74+
$vcrRequest->setHeader('Content-Type', 'text/xml; charset=utf-8;');
75+
$vcrRequest->setHeader('SOAPAction', $action);
76+
77+
} else { // >= SOAP_1_2
78+
$vcrRequest->setHeader('Content-Type', sprintf('application/soap+xml; charset=utf-8; action="%s"', $action));
79+
}
80+
7481
$vcrRequest->setBody($request);
7582

7683
if (!empty($options['login'])) {

tests/VCR/LibraryHooks/SoapHookTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public function testShouldInterceptCallWhenEnabled()
4242

4343
public function testShouldHandleSOAPVersion11()
4444
{
45-
$expectedHeader = 'text/xml; charset=utf-8; action="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"';
46-
$this->soapHook->enable($this->getHeaderCheckCallback($expectedHeader));
45+
$expectedHeaders = array(
46+
'Content-Type' => 'text/xml; charset=utf-8;',
47+
'SOAPAction' => 'http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP',
48+
);
49+
$this->soapHook->enable($this->getHeadersCheckCallback($expectedHeaders));
4750

4851
$client = new \SoapClient(
4952
'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL',
@@ -55,8 +58,11 @@ public function testShouldHandleSOAPVersion11()
5558

5659
public function testShouldHandleSOAPVersion12()
5760
{
58-
$expectedHeader = 'application/soap+xml; charset=utf-8; action="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"';
59-
$this->soapHook->enable($this->getHeaderCheckCallback($expectedHeader));
61+
$expectedHeaders = array(
62+
'Content-Type' => 'application/soap+xml; charset=utf-8; action="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"',
63+
);
64+
65+
$this->soapHook->enable($this->getHeadersCheckCallback($expectedHeaders));
6066

6167
$client = new \SoapClient(
6268
'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL',
@@ -78,14 +84,16 @@ protected function getContentCheckCallback()
7884
}
7985

8086
/**
81-
* @param string $expectedHeader
87+
* @param array $expectedHeaders
8288
* @return \callable
8389
*/
84-
protected function getHeaderCheckCallback($expectedHeader)
90+
protected function getHeadersCheckCallback(array $expectedHeaders)
8591
{
8692
$test = $this;
87-
return function (Request $request) use ($test, $expectedHeader) {
88-
$test->assertEquals($expectedHeader, $request->getHeader('Content-Type'));
93+
return function (Request $request) use ($test, $expectedHeaders) {
94+
foreach ($expectedHeaders as $expectedHeaderName => $expectedHeader) {
95+
$test->assertEquals($expectedHeader, $request->getHeader($expectedHeaderName));
96+
}
8997
return new Response(200, array(), '');
9098
};
9199
}

0 commit comments

Comments
 (0)