function pdo_mysql_tests_valid($namespace, $testClass) { if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) { skip_test($namespace, $testClass, 'PDO MySQL extension not loaded'); } elseif (!is_server_listening($GLOBALS['settings']['mysql']['host'], $GLOBALS['settings']['mysql']['port'])) { skip_test($namespace, $testClass, 'MySQL server not listening'); } elseif (!isset($GLOBALS['settings']['mysql']['db'])) { skip_test($namespace, $testClass, "Please set 'db' in the 'mysql' section of .cachettestrc"); } else { return true; } }
<?php namespace Cachet\Test\Backend; if (!extension_loaded('redis')) { skip_test(__NAMESPACE__, "PHPRedisPrefixTest", "Redis extension not loaded"); } elseif (!is_server_listening($GLOBALS['settings']['redis']['host'], $GLOBALS['settings']['redis']['port'])) { skip_test(__NAMESPACE__, "PHPRedisPrefixTest", "Redis server not listening"); } else { /** * @group backend */ class PHPRedisPrefixTest extends PHPRedisTest { public function getBackend() { $this->backendPrefix = 'prefix/'; return new \Cachet\Backend\PHPRedis($this->redis, 'prefix'); } } }
<?php namespace Cachet\Test\Backend; if (!extension_loaded('xcache')) { skip_test(__NAMESPACE__, "XCacheTest", "xcache extension not loaded"); } else { /** * @group backend */ class XCacheTest extends \Cachet\Test\BackendTestCase { public function getBackend() { xcache_unset_by_prefix("cache"); $backend = new \Cachet\Backend\XCache(); return $backend; } /** * We can't test whether the TTL actually causes an expiration as I * can't work out how to trigger xcache's garbage collection */ public function testWithTTL() { $backend = $this->getBackend(); $dep = new \Cachet\Dependency\TTL(1234); $backend->set(new \Cachet\Item('cache', 'foo', 'bar', $dep)); $item = $backend->get('cache', 'foo'); $this->assertNull($item->dependency); } }
<?php namespace Cachet\Test\Counter; if (!extension_loaded('memcached')) { skip_test(__NAMESPACE__, "MemcachePrefixTest", "Memcached not loaded"); } elseif (!is_server_listening($GLOBALS['settings']['memcached']['host'], $GLOBALS['settings']['memcached']['port'])) { skip_test(__NAMESPACE__, "MemcachePrefixTest", "Memcached not listening"); } else { /** * @group counter */ class MemcachePrefixTest extends MemcacheTest { public function getCounter() { $memcached = new \Memcached(); $memcached->addServer($GLOBALS['settings']['memcached']['host'], $GLOBALS['settings']['memcached']['port']); $memcached->delete('prefix/counter/value'); $memcached->delete('prefix/counter/value2'); return new \Cachet\Counter\Memcache($memcached, 'prefix'); } } }
<?php namespace Cachet\Test\Counter; // TODO: should test both bcmath and gmp versions if (!extension_loaded('bcmath') || !extension_loaded('gmp')) { skip_test(__NAMESPACE__, "SafeCacheTest", "Neither bcmath nor gmp loaded"); } else { /** * @group counter */ class SafeCacheTest extends \Cachet\Test\CounterTestCase { public function getCounter() { $cache = new \Cachet\Cache('counter', new \Cachet\Backend\Memory()); $locker = $this->getMockForAbstractClass('Cachet\\Locker'); return new \Cachet\Counter\SafeCache($cache, $locker); } /** * @dataProvider dataForRangeInfinite */ public function testRangeInfinite($a, $b) { $counter = $this->getCounter(); $result = $counter->increment('count', $a); $this->assertEquals($b, $a); $this->assertEquals($b, $counter->value('count')); } public function dataForRangeInfinite() {
<?php namespace Cachet\Test\Backend; use Cachet\Backend; use Cachet\Cache; if (!extension_loaded('pdo') || !extension_loaded('pdo_sqlite')) { skip_test(__NAMESPACE__, 'PDOSQLiteTest', 'PDO SQLite extension not loaded'); } else { /** * @group backend */ class PDOSQLiteTest extends \Cachet\Test\BackendTestCase { use \Cachet\Test\IterableBackendTest; public function getBackend() { $backend = new Backend\PDO(array('dsn' => 'sqlite::memory:')); $backend->ensureTableExistsForCache("cache1"); $backend->ensureTableExistsForCache("cache2"); return $backend; } } }
<?php namespace Cachet\Test\Backend; if (!extension_loaded('apc') || !extension_loaded('apcu')) { skip_test(__NAMESPACE__, "APCTest", "Neither apc nor apcu loaded"); } elseif (ini_get('apc.enable_cli') != 1) { skip_test(__NAMESPACE__, "APCTest", "apc.enable_cli must be set"); } else { /** * @group apc * @group backend */ class APCTest extends \Cachet\Test\BackendTestCase { use \Cachet\Test\IterableBackendTest; public $backendPrefix; public function getBackend() { apc_clear_cache('user'); $backend = new \Cachet\Backend\APC(); return $backend; } public function testWithTTL() { $backend = $this->getBackend(); $dep = new \Cachet\Dependency\TTL(300); $backend->set(new \Cachet\Item('cache', 'foo', 'bar', $dep)); $iter = new \APCIterator('user', "~^{$this->backendPrefix}cache/foo\$~"); $ttl = $iter->current()['ttl']; // surely not longer than 2 seconds!
<?php namespace Cachet\Test\Backend; use Cachet\Backend; if (!extension_loaded('memcached')) { skip_test(__NAMESPACE__, "MemcacheWithKeyBackendTest", "Memcached not loaded"); } elseif (!is_server_listening($GLOBALS['settings']['memcached']['host'], $GLOBALS['settings']['memcached']['port'])) { skip_test(__NAMESPACE__, "MemcacheWithKeyBackendTest", "Memcached not listening"); } else { /** * @group backend */ class MemcacheWithKeyBackendTest extends \Cachet\Test\BackendTestCase { use \Cachet\Test\IterableBackendTest; public function setUp() { $backend = $this->getBackend(); $backend->connector->connect()->flush(); } public function getBackend() { $memcached = new \Memcached(); $memcached->addServer($GLOBALS['settings']['memcached']['host'], $GLOBALS['settings']['memcached']['port']); $backend = new \Cachet\Backend\Memcache($memcached); $backend->setKeyBackend(new \Cachet\Backend\Memory()); return $backend; } } }
<?php namespace Cachet\Test\Backend; if (!extension_loaded('redis')) { skip_test(__NAMESPACE__, "PHPRedisDeferredConnectionTest", "Redis extension not loaded"); } elseif (!is_server_listening($GLOBALS['settings']['redis']['host'], $GLOBALS['settings']['redis']['port'])) { skip_test(__NAMESPACE__, "PHPRedisDeferredConnectionTest", "Redis server not listening"); } else { /** * @group backend */ class PHPRedisDeferredConnectionTest extends PHPRedisTest { public function getBackend() { return new \Cachet\Backend\PHPRedis($this->getRedisInfo()); } protected function getRedisInfo() { $info = ['host' => $GLOBALS['settings']['redis']['host'], 'port' => isset($GLOBALS['settings']['redis']['port']) ? $GLOBALS['settings']['redis']['port'] : 6379, 'database' => $GLOBALS['settings']['redis']['database']]; return $info; } } }
<?php namespace Cachet\Test\Backend; if (!extension_loaded('xcache')) { skip_test(__NAMESPACE__, "XCacheWithKeyBackendTest", "xcache extension not loaded"); } else { /** * @group backend */ class XCacheWithKeyBackendTest extends XCacheTest { use \Cachet\Test\IterableBackendTest; public function getBackend() { xcache_unset_by_prefix("cache"); $backend = new \Cachet\Backend\XCache(); $backend->setKeyBackend(new \Cachet\Backend\Memory()); return $backend; } } }