From f95a5177b13de5c4b0fee06b7fb49a3c0032f305 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Tue, 11 Oct 2011 21:24:32 +0200 Subject: [PATCH] Fixed typo and added unit tests --- .../SoapCommon/AbstractSoapBuilder.php | 4 +- src/BeSimple/SoapCommon/Cache.php | 4 +- .../SoapCommon/AbstractSoapBuilderTest.php | 61 ++++++++++++++++++- tests/BeSimple/Tests/SoapCommon/CacheTest.php | 12 ++++ .../Tests/SoapCommon/ClassmapTest.php | 8 +-- 5 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/BeSimple/SoapCommon/AbstractSoapBuilder.php b/src/BeSimple/SoapCommon/AbstractSoapBuilder.php index d9e4a78..207893f 100644 --- a/src/BeSimple/SoapCommon/AbstractSoapBuilder.php +++ b/src/BeSimple/SoapCommon/AbstractSoapBuilder.php @@ -99,8 +99,8 @@ abstract class AbstractSoapBuilder public function withWsdlCache($cache) { - if (!in_array($cache, Cache::getTypes())) { - throw new \InvalidArgument(); + if (!in_array($cache, Cache::getTypes(), true)) { + throw new \InvalidArgumentException(); } $this->soapOptions['cache_wsdl'] = $cache; diff --git a/src/BeSimple/SoapCommon/Cache.php b/src/BeSimple/SoapCommon/Cache.php index ce0ef9d..547879f 100644 --- a/src/BeSimple/SoapCommon/Cache.php +++ b/src/BeSimple/SoapCommon/Cache.php @@ -44,7 +44,7 @@ class Cache 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(); } @@ -58,7 +58,7 @@ class Cache 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'); } diff --git a/tests/BeSimple/Tests/SoapCommon/AbstractSoapBuilderTest.php b/tests/BeSimple/Tests/SoapCommon/AbstractSoapBuilderTest.php index ff7dc43..d61fd9e 100644 --- a/tests/BeSimple/Tests/SoapCommon/AbstractSoapBuilderTest.php +++ b/tests/BeSimple/Tests/SoapCommon/AbstractSoapBuilderTest.php @@ -12,8 +12,12 @@ namespace BeSimple\Tests\SoapCommon\Soap; -use BeSimple\Tests\SoapCommon\Fixtures\SoapBuilder; 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 { @@ -67,6 +71,9 @@ class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase { $builder = $this->getSoapBuilder(); + $builder->withWsdlCache(Cache::TYPE_DISK_MEMORY); + $this->assertEquals($this->mergeOptions(array('cache_wsdl' => Cache::TYPE_DISK_MEMORY)), $builder->getSoapOptions()); + $builder->withWsdlCacheNone(); $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()); } + public function testWithWsdlCacheBadValue() + { + $builder = $this->getSoapBuilder(); + + $this->setExpectedException('InvalidArgumentException'); + $builder->withWsdlCache('foo'); + } + public function testWithSingleElementArrays() { $options = $this @@ -131,6 +146,50 @@ class AbstractSoapBuilderTest extends \PHPUnit_Framework_TestCase $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() { $builder = SoapBuilder::createWithDefaults(); diff --git a/tests/BeSimple/Tests/SoapCommon/CacheTest.php b/tests/BeSimple/Tests/SoapCommon/CacheTest.php index f56f192..602f894 100644 --- a/tests/BeSimple/Tests/SoapCommon/CacheTest.php +++ b/tests/BeSimple/Tests/SoapCommon/CacheTest.php @@ -25,6 +25,12 @@ class SoapRequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals(Cache::DISABLED, Cache::isEnabled()); } + public function testSetEnabledBadValue() + { + $this->setExpectedException('InvalidArgumentException'); + Cache::setEnabled('foo'); + } + public function testSetType() { Cache::setType(Cache::TYPE_DISK); @@ -34,6 +40,12 @@ class SoapRequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals(Cache::TYPE_NONE, Cache::getType()); } + public function testSetTypeBadValue() + { + $this->setExpectedException('InvalidArgumentException'); + Cache::setType('foo'); + } + public function testSetDirectory() { \vfsStream::setup('Fixtures'); diff --git a/tests/BeSimple/Tests/SoapCommon/ClassmapTest.php b/tests/BeSimple/Tests/SoapCommon/ClassmapTest.php index a4a97de..2358244 100644 --- a/tests/BeSimple/Tests/SoapCommon/ClassmapTest.php +++ b/tests/BeSimple/Tests/SoapCommon/ClassmapTest.php @@ -42,11 +42,11 @@ class ClassmapTest extends \PHPUnit_Framework_TestCase { $classmap = new Classmap(); - $this->setExpectedException('InvalidArgumentException'); - $classmap->get('foobar'); - $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()