2011-09-03 21:15:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
|
|
|
*
|
|
|
|
* (c) Christian Kerl <christian-kerl@web.de>
|
|
|
|
* (c) Francis Besset <francis.besset@gmail.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2011-09-04 00:42:51 +02:00
|
|
|
namespace BeSimple\Tests\SoapClient;
|
2011-09-03 21:15:51 +02:00
|
|
|
|
2011-09-04 00:36:24 +02:00
|
|
|
use BeSimple\SoapCommon\Cache;
|
2011-10-08 15:07:49 +02:00
|
|
|
use BeSimple\SoapCommon\Classmap;
|
2011-09-10 19:33:27 +02:00
|
|
|
use BeSimple\SoapCommon\Converter\DateTimeTypeConverter;
|
|
|
|
use BeSimple\SoapCommon\Converter\DateTypeConverter;
|
|
|
|
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
2011-09-04 00:42:51 +02:00
|
|
|
use BeSimple\SoapClient\SoapClient;
|
2011-09-03 21:15:51 +02:00
|
|
|
|
|
|
|
class SoapClientTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testSetOptions()
|
|
|
|
{
|
|
|
|
$soapClient = new SoapClient('foo.wsdl');
|
|
|
|
$options = array(
|
2011-09-04 12:15:11 +02:00
|
|
|
'cache_type' => Cache::TYPE_DISK_MEMORY,
|
2011-09-04 00:36:24 +02:00
|
|
|
'debug' => true,
|
2011-09-04 23:42:03 +02:00
|
|
|
'namespace' => 'foo',
|
2011-09-03 21:15:51 +02:00
|
|
|
);
|
|
|
|
$soapClient->setOptions($options);
|
|
|
|
|
2011-10-09 20:10:13 +02:00
|
|
|
$this->assertEquals(array_merge($options, array('exceptions' => true, 'user_agent' => 'BeSimpleSoap')), $soapClient->getOptions());
|
2011-09-03 21:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetOptionsThrowsAnExceptionIfOptionsDoesNotExists()
|
|
|
|
{
|
|
|
|
$soapClient = new SoapClient('foo.wsdl');
|
|
|
|
|
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
|
|
|
$soapClient->setOptions(array('bad_option' => true));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetOption()
|
|
|
|
{
|
|
|
|
$soapClient = new SoapClient('foo.wsdl');
|
|
|
|
$soapClient->setOption('debug', true);
|
|
|
|
|
|
|
|
$this->assertEquals(true, $soapClient->getOption('debug'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetOptionThrowsAnExceptionIfOptionDoesNotExists()
|
|
|
|
{
|
|
|
|
$soapClient = new SoapClient('foo.wsdl');
|
|
|
|
|
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
|
|
|
$soapClient->setOption('bad_option', 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetOptionThrowsAnExceptionIfOptionDoesNotExists()
|
|
|
|
{
|
|
|
|
$soapClient = new SoapClient('foo.wsdl');
|
|
|
|
|
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
|
|
|
$soapClient->getOption('bad_option');
|
|
|
|
}
|
|
|
|
|
2011-09-04 23:42:03 +02:00
|
|
|
public function testCreateSoapHeader()
|
|
|
|
{
|
2011-10-08 12:22:17 +02:00
|
|
|
$soapClient = new SoapClient('foo.wsdl', array('namespace' => 'http://foobar/soap/User/1.0/'));
|
2011-09-04 23:42:03 +02:00
|
|
|
$soapHeader = $soapClient->createSoapHeader('foo', 'bar');
|
|
|
|
|
|
|
|
$this->assertInstanceOf('SoapHeader', $soapHeader);
|
|
|
|
$this->assertEquals('http://foobar/soap/User/1.0/', $soapHeader->namespace);
|
|
|
|
$this->assertEquals('foo', $soapHeader->name);
|
|
|
|
$this->assertEquals('bar', $soapHeader->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateSoapHeaderThrowsAnExceptionIfNamespaceIsNull()
|
|
|
|
{
|
|
|
|
$soapClient = new SoapClient('foo.wsdl');
|
|
|
|
|
|
|
|
$this->setExpectedException('RuntimeException');
|
|
|
|
$soapHeader = $soapClient->createSoapHeader('foo', 'bar');
|
|
|
|
}
|
|
|
|
|
2011-09-03 21:15:51 +02:00
|
|
|
public function testGetSoapOptions()
|
|
|
|
{
|
2011-09-04 00:36:24 +02:00
|
|
|
Cache::setType(Cache::TYPE_MEMORY);
|
2011-10-08 12:22:17 +02:00
|
|
|
$soapClient = new SoapClient('foo.wsdl', array('debug' => true));
|
2011-10-09 20:10:13 +02:00
|
|
|
$this->assertEquals(array('cache_wsdl' => Cache::getType(), 'trace' => true, 'classmap' => array(), 'exceptions' => true, 'typemap' => array(), 'user_agent' => 'BeSimpleSoap'), $soapClient->getSoapOptions());
|
2011-09-03 21:15:51 +02:00
|
|
|
|
2011-10-08 12:22:17 +02:00
|
|
|
$soapClient = new SoapClient('foo.wsdl', array('debug' => false, 'cache_type' => Cache::TYPE_NONE));
|
2011-10-09 20:10:13 +02:00
|
|
|
$this->assertEquals(array('cache_wsdl' => Cache::TYPE_NONE, 'trace' => false, 'classmap' => array(), 'exceptions' => true, 'typemap' => array(), 'user_agent' => 'BeSimpleSoap'), $soapClient->getSoapOptions());
|
2011-10-08 15:07:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSoapOptionsWithClassmap()
|
|
|
|
{
|
|
|
|
$classmap = new Classmap();
|
|
|
|
|
|
|
|
$soapClient = new SoapClient('foo.wsdl', array(), $classmap);
|
|
|
|
$soapOptions = $soapClient->getSoapOptions();
|
|
|
|
|
|
|
|
$this->assertSame(array(), $soapOptions['classmap']);
|
|
|
|
|
|
|
|
$map = array(
|
|
|
|
'foobar' => 'BeSimple\SoapClient\SoapClient',
|
|
|
|
'barfoo' => 'BeSimple\SoapClient\Tests\SoapClientTest',
|
|
|
|
);
|
|
|
|
$classmap->set($map);
|
|
|
|
$soapOptions = $soapClient->getSoapOptions();
|
|
|
|
|
|
|
|
$this->assertSame($map, $soapOptions['classmap']);
|
2011-09-10 19:33:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSoapOptionsWithTypemap()
|
|
|
|
{
|
|
|
|
$converters = new TypeConverterCollection();
|
|
|
|
|
|
|
|
$dateTimeTypeConverter = new DateTimeTypeConverter();
|
|
|
|
$converters->add($dateTimeTypeConverter);
|
|
|
|
|
|
|
|
$dateTypeConverter = new DateTypeConverter();
|
|
|
|
$converters->add($dateTypeConverter);
|
|
|
|
|
2011-10-08 15:07:49 +02:00
|
|
|
$soapClient = new SoapClient('foo.wsdl', array(), null, $converters);
|
2011-09-10 19:33:27 +02:00
|
|
|
$soapOptions = $soapClient->getSoapOptions();
|
|
|
|
|
|
|
|
$this->assertEquals('http://www.w3.org/2001/XMLSchema', $soapOptions['typemap'][0]['type_ns']);
|
|
|
|
$this->assertEquals('dateTime', $soapOptions['typemap'][0]['type_name']);
|
|
|
|
$this->assertInstanceOf('Closure', $soapOptions['typemap'][0]['from_xml']);
|
|
|
|
$this->assertInstanceOf('Closure', $soapOptions['typemap'][0]['to_xml']);
|
|
|
|
|
|
|
|
$this->assertEquals('http://www.w3.org/2001/XMLSchema', $soapOptions['typemap'][1]['type_ns']);
|
|
|
|
$this->assertEquals('date', $soapOptions['typemap'][1]['type_name']);
|
|
|
|
$this->assertInstanceOf('Closure', $soapOptions['typemap'][1]['from_xml']);
|
|
|
|
$this->assertInstanceOf('Closure', $soapOptions['typemap'][1]['to_xml']);
|
2011-09-03 21:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNativeSoapClient()
|
|
|
|
{
|
2011-10-08 12:22:17 +02:00
|
|
|
$soapClient = new SoapClient(__DIR__.'/Fixtures/foobar.wsdl', array('debug' => true));
|
2011-09-03 21:15:51 +02:00
|
|
|
|
|
|
|
$this->assertInstanceOf('SoapClient', $soapClient->getNativeSoapClient());
|
|
|
|
}
|
|
|
|
}
|