Skip to content

Commit 89d7048

Browse files
committed
adds SOAPAction header for soap 1.1
1 parent eacf5f3 commit 89d7048

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/VCR/LibraryHooks/SoapHook.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ 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+
switch ($version) {
74+
case SOAP_1_1:
75+
$vcrRequest->setHeader('Content-Type', 'text/xml; charset=utf-8;');
76+
$vcrRequest->setHeader('SOAPAction', $action);
77+
break;
78+
79+
case SOAP_1_2:
80+
$vcrRequest->setHeader('Content-Type', sprintf('application/soap+xml; charset=utf-8; action="%s"', $action));
81+
break;
82+
}
83+
7484
$vcrRequest->setBody($request);
7585

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

tests/VCR/LibraryHooks/SoapHookTest.php

Lines changed: 20 additions & 2 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 = [
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',
@@ -89,4 +92,19 @@ protected function getHeaderCheckCallback($expectedHeader)
8992
return new Response(200, array(), '');
9093
};
9194
}
95+
96+
/**
97+
* @param array $expectedHeaders
98+
* @return \callable
99+
*/
100+
protected function getHeadersCheckCallback(array $expectedHeaders)
101+
{
102+
$test = $this;
103+
return function (Request $request) use ($test, $expectedHeaders) {
104+
foreach ($expectedHeaders as $expectedHeaderName => $expectedHeader) {
105+
$test->assertEquals($expectedHeader, $request->getHeader($expectedHeaderName));
106+
}
107+
return new Response(200, array(), '');
108+
};
109+
}
92110
}

0 commit comments

Comments
 (0)