Skip to content

Commit 18b313e

Browse files
author
laland
committed
[SoapHook] switches from switch statement to if in SOAP version resolution, removes getHeaderCheckCallback from SoapHookTest in favour of getHeadersCheckCallback
1 parent d1251da commit 18b313e

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/VCR/LibraryHooks/SoapHook.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,12 @@ public function doRequest($request, $location, $action, $version, $one_way = 0,
7070

7171
$vcrRequest = new Request('POST', $location);
7272

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;
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));
8279
}
8380

8481
$vcrRequest->setBody($request);

tests/VCR/LibraryHooks/SoapHookTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ public function testShouldHandleSOAPVersion11()
5858

5959
public function testShouldHandleSOAPVersion12()
6060
{
61-
$expectedHeader = 'application/soap+xml; charset=utf-8; action="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"';
62-
$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));
6366

6467
$client = new \SoapClient(
6568
'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL',
@@ -80,19 +83,6 @@ protected function getContentCheckCallback()
8083
};
8184
}
8285

83-
/**
84-
* @param string $expectedHeader
85-
* @return \callable
86-
*/
87-
protected function getHeaderCheckCallback($expectedHeader)
88-
{
89-
$test = $this;
90-
return function (Request $request) use ($test, $expectedHeader) {
91-
$test->assertEquals($expectedHeader, $request->getHeader('Content-Type'));
92-
return new Response(200, array(), '');
93-
};
94-
}
95-
9686
/**
9787
* @param array $expectedHeaders
9888
* @return \callable

0 commit comments

Comments
 (0)