Initial commit
This commit is contained in:
commit
5dc84ef088
31
phpunit.xml.dist
Normal file
31
phpunit.xml.dist
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="BeSimple\SoapCommon Test Suite">
|
||||
<directory>./tests/BeSimple/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>benchmark</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./src/BeSimple/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
107
src/BeSimple/SoapCommon/Cache.php
Normal file
107
src/BeSimple/SoapCommon/Cache.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
72
tests/BeSimple/Tests/SoapCommon/CacheTest.php
Normal file
72
tests/BeSimple/Tests/SoapCommon/CacheTest.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
22
tests/bootstrap.php
Normal file
22
tests/bootstrap.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
// register silently failing autoloader
|
||||
spl_autoload_register(function($class) {
|
||||
if (0 === strpos($class, 'BeSimple\Tests\\')) {
|
||||
$path = __DIR__.'/../'.strtr($class, '\\', '/').'.php';
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
require_once $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (0 === strpos($class, 'BeSimple\SoapCommon\\')) {
|
||||
$path = __DIR__.'/../src/'.($class = strtr($class, '\\', '/')).'.php';
|
||||
if (file_exists($path) && is_readable($path)) {
|
||||
require_once $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user