Skip to content

Commit 8dd9e79

Browse files
committed
Merge branch 'release/1.0.0'
2 parents 3ccda03 + 9453440 commit 8dd9e79

File tree

5 files changed

+155
-19
lines changed

5 files changed

+155
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ before_install:
1212
- composer self-update
1313

1414
install:
15-
- composer install
15+
- composer install --no-dev
1616

1717
script:
1818
- phpunit --coverage-text --coverage-clover=coverage.clover

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
1.0.0
5+
---------
6+
- First major release, code coverage improved to reach 100% from the 1.0.0RC02 release.
7+
48
1.0.0RC02
59
---------
610
- Major: update source code structure, put all classes under ```src``` folder, rename Tests to tests, update composer and phpunit accordingly

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ So, basically, you MUST at least override the methods declared by the PHP interf
4444
#### Description
4545
This interface must be used to define a new [SoapClient](http://php.net/manual/en/class.soapclient.php) base class for any ```ServiceType``` class generated by [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator).
4646

47-
#### What has to be implemented?
48-
Here are the constants defined by this interface and their utility:
47+
#### Options
48+
Here are the constants/options defined by this interface and their utility:
4949
- **DEFAULT_SOAP_CLIENT_CLASS = '\SoapClient'**: this is the default [SoapClient](http://php.net/manual/en/class.soapclient.php) class that is used to send the request. Feel free to override it if you want to use another [SoapClient](http://php.net/manual/en/class.soapclient.php) class
5050
- **OPTION_PREFIX**: this is the prefix used for any constant's option name
5151
- **WSDL_URL**: option index used to pass the WSDL url
@@ -73,6 +73,7 @@ Here are the constants defined by this interface and their utility:
7373
- **WSDL_AUTHENTICATION**: authentication method may be either ```SOAP_AUTHENTICATION_BASIC``` (default) or ```SOAP_AUTHENTICATION_DIGEST```
7474
- **WSDL_SSL_METHOD**: one of ```SOAP_SSL_METHOD_TLS```, ```SOAP_SSL_METHOD_SSLv2```, ```SOAP_SSL_METHOD_SSLv3``` or ```SOAP_SSL_METHOD_SSLv23```
7575

76+
#### What has to be implemented?
7677
Here are the methods that must be implemented and why:
7778
- **__construct(array $wsdlOptions = array(), $resetSoapClient = true)**: the constructor must be able to handl one of the listed constants above
7879
- **getSoapClient()**: must return the [SoapClient](http://php.net/manual/en/class.soapclient.php) object that is responsible fo sending the requests.

src/AbstractSoapClientBase.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function initSoapClient(array $options)
6767
{
6868
$wsdlOptions = array();
6969
$defaultWsdlOptions = self::getDefaultWsdlOptions();
70-
foreach ($defaultWsdlOptions as $optioName=>$optionValue) {
70+
foreach ($defaultWsdlOptions as $optioName => $optionValue) {
7171
if (array_key_exists($optioName, $options) && !empty($options[$optioName])) {
7272
$wsdlOptions[str_replace(self::OPTION_PREFIX, '', $optioName)] = $options[$optioName];
7373
} elseif (!empty($optionValue)) {
@@ -292,8 +292,8 @@ public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false,
292292
{
293293
if (self::getSoapClient()) {
294294
$defaultHeaders = (isset(self::getSoapClient()->__default_headers) && is_array(self::getSoapClient()->__default_headers)) ? self::getSoapClient()->__default_headers : array();
295-
foreach ($defaultHeaders as $index=>$soapheader) {
296-
if ($soapheader->name === $name) {
295+
foreach ($defaultHeaders as $index => $soapHeader) {
296+
if ($soapHeader->name === $name) {
297297
unset($defaultHeaders[$index]);
298298
break;
299299
}
@@ -319,6 +319,7 @@ public function setSoapHeader($nameSpace, $name, $data, $mustUnderstand = false,
319319
*/
320320
public function setHttpHeader($headerName, $headerValue)
321321
{
322+
$state = false;
322323
if (self::getSoapClient() && !empty($headerName)) {
323324
$streamContext = (isset(self::getSoapClient()->_stream_context) && is_resource(self::getSoapClient()->_stream_context)) ? self::getSoapClient()->_stream_context : null;
324325
if (!is_resource($streamContext)) {
@@ -327,17 +328,11 @@ public function setHttpHeader($headerName, $headerValue)
327328
$options['http']['header'] = '';
328329
} else {
329330
$options = stream_context_get_options($streamContext);
330-
if (is_array($options)) {
331-
if (!array_key_exists('http', $options) || !is_array($options['http'])) {
332-
$options['http'] = array();
333-
$options['http']['header'] = '';
334-
} elseif (!array_key_exists('header', $options['http'])) {
335-
$options['http']['header'] = '';
336-
}
337-
} else {
338-
$options = array();
331+
if (!array_key_exists('http', $options) || !is_array($options['http'])) {
339332
$options['http'] = array();
340333
$options['http']['header'] = '';
334+
} elseif (!array_key_exists('header', $options['http'])) {
335+
$options['http']['header'] = '';
341336
}
342337
}
343338
if (count($options) && array_key_exists('http', $options) && is_array($options['http']) && array_key_exists('header', $options['http']) && is_string($options['http']['header'])) {
@@ -363,17 +358,16 @@ public function setHttpHeader($headerName, $headerValue)
363358
* Create context if it does not exist
364359
*/
365360
if (!is_resource($streamContext)) {
366-
return (self::getSoapClient()->_stream_context = stream_context_create($options)) ? true : false;
361+
$state = (self::getSoapClient()->_stream_context = stream_context_create($options)) ? true : false;
367362
} else {
368363
/**
369364
* Set the new context http header option
370365
*/
371-
return stream_context_set_option(self::getSoapClient()->_stream_context, 'http', 'header', $options['http']['header']);
366+
$state = stream_context_set_option(self::getSoapClient()->_stream_context, 'http', 'header', $options['http']['header']);
372367
}
373368
}
374-
return false;
375369
}
376-
return false;
370+
return $state;
377371
}
378372
/**
379373
* Method returning last errors occured during the calls

tests/SoapClientTest.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,143 @@ public function testSetHeaders()
214214
),
215215
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
216216
}
217+
/**
218+
*
219+
*/
220+
public function testSetHeadersOnExistingHeaders()
221+
{
222+
$soapClient = new SoapClient(array(
223+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
224+
SoapClient::WSDL_CLASSMAP => self::classMap(),
225+
));
226+
227+
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
228+
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
229+
230+
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
231+
232+
$this->assertSame(array(
233+
'http' => array(
234+
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
235+
'X-Header-ID: X-Header-ID-Value',
236+
),
237+
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
238+
}
239+
/**
240+
*
241+
*/
242+
public function testSetHeadersOnExistingHttpsHeaders()
243+
{
244+
$streamContext = stream_context_create(array(
245+
'https' => array(
246+
'header' => array(
247+
'X-HEADER' => 'X-VALUE',
248+
),
249+
),
250+
));
251+
$soapClient = new SoapClient(array(
252+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
253+
SoapClient::WSDL_CLASSMAP => self::classMap(),
254+
SoapClient::WSDL_STREAM_CONTEXT => $streamContext,
255+
));
256+
257+
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
258+
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
259+
260+
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
261+
262+
$this->assertSame(array(
263+
'https' => array(
264+
'header' => array(
265+
'X-HEADER' => 'X-VALUE',
266+
),
267+
),
268+
'http' => array(
269+
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
270+
'X-Header-ID: X-Header-ID-Value',
271+
),
272+
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
273+
}
274+
/**
275+
*
276+
*/
277+
public function testSetHeadersOnExistingHttpHeaders()
278+
{
279+
$streamContext = stream_context_create(array(
280+
'http' => array(
281+
'Auth' => array(
282+
'X-HEADER' => 'X-VALUE',
283+
),
284+
),
285+
));
286+
$soapClient = new SoapClient(array(
287+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
288+
SoapClient::WSDL_CLASSMAP => self::classMap(),
289+
SoapClient::WSDL_STREAM_CONTEXT => $streamContext,
290+
));
291+
292+
$this->assertTrue($soapClient->setHttpHeader('X-Header-Name', 'X-Header-Value'));
293+
$this->assertTrue($soapClient->setHttpHeader('X-Header-ID', 'X-Header-ID-Value'));
294+
295+
$this->assertTrue(is_resource(SoapClient::getSoapClient()->_stream_context));
296+
297+
$this->assertSame(array(
298+
'http' => array(
299+
'Auth' => array(
300+
'X-HEADER' => 'X-VALUE',
301+
),
302+
'header' => 'X-Header-Name: X-Header-Value' . "\r\n" .
303+
'X-Header-ID: X-Header-ID-Value',
304+
),
305+
), stream_context_get_options(SoapClient::getSoapClient()->_stream_context));
306+
}
307+
/**
308+
*
309+
*/
310+
public function testSetSoapHeader()
311+
{
312+
$soapClient = new SoapClient(array(
313+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
314+
SoapClient::WSDL_CLASSMAP => self::classMap(),
315+
));
316+
317+
$soapClient->setSoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false, null);
318+
319+
$this->assertEquals(array(
320+
new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false),
321+
), SoapClient::getSoapClient()->__default_headers);
322+
}
323+
/**
324+
*
325+
*/
326+
public function testSetSoapHeaderModified()
327+
{
328+
$soapClient = new SoapClient(array(
329+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
330+
SoapClient::WSDL_CLASSMAP => self::classMap(),
331+
));
332+
333+
$soapClient->setSoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false, null);
334+
$soapClient->setSoapHeader('urn:namespace', 'HeaderAuth', 'the-data-modified', false, null);
335+
336+
$this->assertEquals(new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data-modified', false), array_pop(SoapClient::getSoapClient()->__default_headers));
337+
}
338+
/**
339+
*
340+
*/
341+
public function testSetSoapActor()
342+
{
343+
$soapClient = new SoapClient(array(
344+
SoapClient::WSDL_URL => __DIR__ . '/resources/bingsearch.wsdl',
345+
SoapClient::WSDL_CLASSMAP => self::classMap(),
346+
));
347+
348+
$soapClient->setSoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false, 'actor');
349+
350+
$this->assertEquals(array(
351+
new \SoapHeader('urn:namespace', 'HeaderAuth', 'the-data', false, 'actor'),
352+
), SoapClient::getSoapClient()->__default_headers);
353+
}
217354
/**
218355
* @return string[]
219356
*/

0 commit comments

Comments
 (0)