Fixed typo and added unit tests

This commit is contained in:
Francis Besset 2011-10-11 21:24:32 +02:00
parent 0f30119294
commit f95a5177b1
5 changed files with 80 additions and 9 deletions

View File

@ -99,8 +99,8 @@ abstract class AbstractSoapBuilder
public function withWsdlCache($cache) public function withWsdlCache($cache)
{ {
if (!in_array($cache, Cache::getTypes())) { if (!in_array($cache, Cache::getTypes(), true)) {
throw new \InvalidArgument(); throw new \InvalidArgumentException();
} }
$this->soapOptions['cache_wsdl'] = $cache; $this->soapOptions['cache_wsdl'] = $cache;

View File

@ -44,7 +44,7 @@ class Cache
static public function setEnabled($enabled) static public function setEnabled($enabled)
{ {
if (!in_array($enabled, array(self::ENABLED, self::DISABLED))) { if (!in_array($enabled, array(self::ENABLED, self::DISABLED), true)) {
throw new \InvalidArgumentException(); throw new \InvalidArgumentException();
} }
@ -58,7 +58,7 @@ class Cache
static public function setType($type) static public function setType($type)
{ {
if (!in_array($type, self::getTypes())) { if (!in_array($type, self::getTypes(), true)) {
throw new \InvalidArgumentException('The cache type has to be either Cache::TYPE_NONE, Cache::TYPE_DISK, Cache::TYPE_MEMORY or Cache::TYPE_DISK_MEMORY'); throw new \InvalidArgumentException('The cache type has to be either Cache::TYPE_NONE, Cache::TYPE_DISK, Cache::TYPE_MEMORY or Cache::TYPE_DISK_MEMORY');
} }

View File

@ -12,8 +12,12 @@
namespace BeSimple\Tests\SoapCommon\Soap; namespace BeSimple\Tests\SoapCommon\Soap;
use BeSimple\Tests\SoapCommon\Fixtures\SoapBuilder;
use BeSimple\SoapCommon\Cache; use BeSimple\SoapCommon\Cache;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\DateTimeTypeConverter;
use BeSimple\SoapCommon\Converter\DateTypeConverter;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use BeSimple\Tests\SoapCommon\Fixtures\SoapBuilder;
class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase
{ {
@ -67,6 +71,9 @@ class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase
{ {
$builder = $this->getSoapBuilder(); $builder = $this->getSoapBuilder();
$builder->withWsdlCache(Cache::TYPE_DISK_MEMORY);
$this->assertEquals($this->mergeOptions(array('cache_wsdl' => Cache::TYPE_DISK_MEMORY)), $builder->getSoapOptions());
$builder->withWsdlCacheNone(); $builder->withWsdlCacheNone();
$this->assertEquals($this->mergeOptions(array('cache_wsdl' => Cache::TYPE_NONE)), $builder->getSoapOptions()); $this->assertEquals($this->mergeOptions(array('cache_wsdl' => Cache::TYPE_NONE)), $builder->getSoapOptions());
@ -80,6 +87,14 @@ class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->mergeOptions(array('cache_wsdl' => Cache::TYPE_DISK_MEMORY)), $builder->getSoapOptions()); $this->assertEquals($this->mergeOptions(array('cache_wsdl' => Cache::TYPE_DISK_MEMORY)), $builder->getSoapOptions());
} }
public function testWithWsdlCacheBadValue()
{
$builder = $this->getSoapBuilder();
$this->setExpectedException('InvalidArgumentException');
$builder->withWsdlCache('foo');
}
public function testWithSingleElementArrays() public function testWithSingleElementArrays()
{ {
$options = $this $options = $this
@ -131,6 +146,50 @@ class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($this->mergeOptions(array('features' => $features)), $builder->getSoapOptions()); $this->assertEquals($this->mergeOptions(array('features' => $features)), $builder->getSoapOptions());
} }
public function testWithTypeConverters()
{
$builder = $this->getSoapBuilder();
$builder->withTypeConverter(new DateTypeConverter());
$options = $builder->getSoapOptions();
$this->assertEquals(1, count($options['typemap']));
$converters = new TypeConverterCollection();
$converters->add(new DateTimeTypeConverter());
$builder->withTypeConverters($converters);
$options = $builder->getSoapOptions();
$this->assertEquals(2, count($options['typemap']));
$builder->withTypeConverters($converters, false);
$options = $builder->getSoapOptions();
$this->assertEquals(1, count($options['typemap']));
}
public function testClassmap()
{
$builder = $this->getSoapBuilder();
$builder->withClassMapping('foo', __CLASS__);
$options = $builder->getSoapOptions();
$this->assertEquals(1, count($options['classmap']));
$classmap = new Classmap();
$classmap->add('bar', __CLASS__);
$builder->withClassmap($classmap);
$options = $builder->getSoapOptions();
$this->assertEquals(2, count($options['classmap']));
$builder->withClassmap($classmap, false);
$options = $builder->getSoapOptions();
$this->assertEquals(1, count($options['classmap']));
}
public function testCreateWithDefaults() public function testCreateWithDefaults()
{ {
$builder = SoapBuilder::createWithDefaults(); $builder = SoapBuilder::createWithDefaults();

View File

@ -25,6 +25,12 @@ class SoapRequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(Cache::DISABLED, Cache::isEnabled()); $this->assertEquals(Cache::DISABLED, Cache::isEnabled());
} }
public function testSetEnabledBadValue()
{
$this->setExpectedException('InvalidArgumentException');
Cache::setEnabled('foo');
}
public function testSetType() public function testSetType()
{ {
Cache::setType(Cache::TYPE_DISK); Cache::setType(Cache::TYPE_DISK);
@ -34,6 +40,12 @@ class SoapRequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(Cache::TYPE_NONE, Cache::getType()); $this->assertEquals(Cache::TYPE_NONE, Cache::getType());
} }
public function testSetTypeBadValue()
{
$this->setExpectedException('InvalidArgumentException');
Cache::setType('foo');
}
public function testSetDirectory() public function testSetDirectory()
{ {
\vfsStream::setup('Fixtures'); \vfsStream::setup('Fixtures');

View File

@ -42,11 +42,11 @@ class ClassmapTest extends \PHPUnit_Framework_TestCase
{ {
$classmap = new Classmap(); $classmap = new Classmap();
$this->setExpectedException('InvalidArgumentException');
$classmap->get('foobar');
$classmap->add('foobar', 'BeSimple\SoapCommon\Classmap'); $classmap->add('foobar', 'BeSimple\SoapCommon\Classmap');
$this->assertSame(array('foobar' => 'BeSimple\SoapCommon\Classmap'), $classmap->get('foobar')); $this->assertSame('BeSimple\SoapCommon\Classmap', $classmap->get('foobar'));
$this->setExpectedException('InvalidArgumentException');
$classmap->get('bar');
} }
public function testSet() public function testSet()