Skip to content

Commit 384df1e

Browse files
committed
Adds test for SOAP version 1.1 and 1.2 checks.
1 parent ddadc19 commit 384df1e

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

tests/VCR/LibraryHooks/SoapTest.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function setup()
2929

3030
public function testShouldInterceptCallWhenEnabled()
3131
{
32-
$this->soapHook->enable($this->getTestCallback());
32+
$this->soapHook->enable($this->getContentCheckCallback());
3333

3434
$client = new \SoapClient('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL', array('soap_version' => SOAP_1_2));
3535
$client->setLibraryHook($this->soapHook);
@@ -52,16 +52,56 @@ public function testShouldNotInterceptCallWhenDisabled()
5252
$this->assertInstanceOf('\stdClass', $actual, 'Response was not returned.');
5353
}
5454

55+
public function testShouldHandleSOAPVersion11()
56+
{
57+
$expectedHeader = 'text/xml; charset=utf-8; action="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"';
58+
$this->soapHook->enable($this->getHeaderCheckCallback($expectedHeader));
59+
60+
$client = new \SoapClient(
61+
'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL',
62+
array('soap_version' => SOAP_1_1)
63+
);
64+
$client->setLibraryHook($this->soapHook);
65+
$client->GetCityWeatherByZIP(array('ZIP' => '10013'));
66+
}
67+
68+
public function testShouldHandleSOAPVersion12()
69+
{
70+
$expectedHeader = 'application/soap+xml; charset=utf-8; action="http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP"';
71+
$this->soapHook->enable($this->getHeaderCheckCallback($expectedHeader));
72+
73+
$client = new \SoapClient(
74+
'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL',
75+
array('soap_version' => SOAP_1_2)
76+
);
77+
$client->setLibraryHook($this->soapHook);
78+
$client->GetCityWeatherByZIP(array('ZIP' => '10013'));
79+
}
80+
5581
/**
5682
* @param null $handleRequestCallback
5783
*
5884
* @return \callable
5985
*/
60-
protected function getTestCallback($handleRequestCallback = null)
86+
protected function getContentCheckCallback()
6187
{
6288
$testClass = $this;
63-
return function($request) use($testClass) {
89+
return function () use ($testClass) {
6490
return new Response(200, null, $testClass->expected);
6591
};
6692
}
93+
94+
/**
95+
* @param null $handleRequestCallback
96+
*
97+
* @return \callable
98+
*/
99+
protected function getHeaderCheckCallback($expectedHeader)
100+
{
101+
$test = $this;
102+
return function ($request) use ($test, $expectedHeader) {
103+
$test->assertEquals($expectedHeader, $request->getHeader('Content-Type'));
104+
return new Response(200, null, '');
105+
};
106+
}
67107
}

0 commit comments

Comments
 (0)