From 5dc84ef088cdcc6916d5c30bfaace1e1159cae51 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 4 Sep 2011 00:29:19 +0200 Subject: [PATCH] Initial commit --- phpunit.xml.dist | 31 +++++ src/BeSimple/SoapCommon/Cache.php | 107 ++++++++++++++++++ tests/BeSimple/Tests/SoapCommon/CacheTest.php | 72 ++++++++++++ tests/bootstrap.php | 22 ++++ 4 files changed, 232 insertions(+) create mode 100644 phpunit.xml.dist create mode 100644 src/BeSimple/SoapCommon/Cache.php create mode 100644 tests/BeSimple/Tests/SoapCommon/CacheTest.php create mode 100644 tests/bootstrap.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..e719cf2 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + ./tests/BeSimple/ + + + + + + benchmark + + + + + + ./src/BeSimple/ + + + diff --git a/src/BeSimple/SoapCommon/Cache.php b/src/BeSimple/SoapCommon/Cache.php new file mode 100644 index 0000000..c4213a8 --- /dev/null +++ b/src/BeSimple/SoapCommon/Cache.php @@ -0,0 +1,107 @@ + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapCommon; + +/** + * @author Francis Besset + */ +class Cache +{ + const DISABLED = 0; + const ENABLED = 1; + + const TYPE_NONE = WSDL_CACHE_NONE; + const TYPE_DISK = WSDL_CACHE_DISK; + const TYPE_MEMORY = WSDL_CACHE_MEMORY; + const TYPE_DISK_MEMORY = WSDL_CACHE_BOTH; + + static protected $types = array( + self::TYPE_NONE, + self::TYPE_DISK, + self::TYPE_MEMORY, + self::TYPE_DISK_MEMORY, + ); + + static public function getTypes() + { + return self::$types; + } + + static public function isEnabled() + { + return self::iniGet('soap.wsdl_cache_enabled'); + } + + static public function setEnabled($enabled) + { + if (!in_array($enabled, array(self::ENABLED, self::DISABLED))) { + throw new \InvalidArgumentException(); + } + + self::iniSet('soap.wsdl_cache_enabled', $enabled); + } + + static public function getType() + { + return self::iniGet('soap.wsdl_cache'); + } + + static public function setType($type) + { + if (!in_array($type, self::getTypes())) { + throw new \InvalidArgumentException(); + } + + self::iniSet('soap.wsdl_cache', $type); + } + + static public function getDirectory() + { + return self::iniGet('soap.wsdl_cache_dir'); + } + + static public function setDirectory($directory) + { + self::iniSet('soap.wsdl_cache_dir', $directory); + } + + static public function getLifetime() + { + return self::iniGet('soap.wsdl_cache_ttl'); + } + + static public function setLifetime($lifetime) + { + self::iniSet('soap.wsdl_cache_ttl', $lifetime); + } + + static public function getLimit() + { + return self::iniGet('soap.wsdl_cache_limit'); + } + + static public function setLimit($limit) + { + self::iniSet('soap.wsdl_cache_limit', $limit); + } + + static protected function iniGet($key) + { + return ini_get($key); + } + + static protected function iniSet($key, $value) + { + ini_set($key, $value); + } +} \ No newline at end of file diff --git a/tests/BeSimple/Tests/SoapCommon/CacheTest.php b/tests/BeSimple/Tests/SoapCommon/CacheTest.php new file mode 100644 index 0000000..aebe217 --- /dev/null +++ b/tests/BeSimple/Tests/SoapCommon/CacheTest.php @@ -0,0 +1,72 @@ + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\Tests\SoapCommon\Soap; + +use BeSimple\SoapCommon\Cache; + +class SoapRequestTest extends \PHPUnit_Framework_TestCase +{ + public function testSetEnabled() + { + Cache::setEnabled(Cache::ENABLED); + $this->assertEquals(Cache::ENABLED, Cache::isEnabled()); + + Cache::setEnabled(Cache::DISABLED); + $this->assertEquals(Cache::DISABLED, Cache::isEnabled()); + } + + public function testSetType() + { + Cache::setType(Cache::TYPE_DISK); + $this->assertEquals(Cache::TYPE_DISK, Cache::getType()); + + Cache::setType(Cache::TYPE_NONE); + $this->assertEquals(Cache::TYPE_NONE, Cache::getType()); + } + + public function testSetDirectory() + { + Cache::setDirectory('/foo'); + $this->assertEquals('/foo', Cache::getDirectory()); + + Cache::setDirectory('/bar'); + $this->assertEquals('/bar', Cache::getDirectory()); + } + + public function testSetLifetime() + { + Cache::setLifetime(1234); + $this->assertEquals(1234, Cache::getLifetime()); + + Cache::setLifetime(4321); + $this->assertEquals(4321, Cache::getLifetime()); + } + + public function testSetLimit() + { + Cache::setLimit(10); + $this->assertEquals(10, Cache::getLimit()); + + Cache::setLimit(1); + $this->assertEquals(1, Cache::getLimit()); + } + + public function setUp() + { + ini_restore('soap.wsdl_cache_enabled'); + ini_restore('soap.wsdl_cache'); + ini_restore('soap.wsdl_cache_dir'); + ini_restore('soap.wsdl_cache_ttl'); + ini_restore('soap.wsdl_cache_limit'); + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..96aebb6 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,22 @@ +