2016-04-12 19:31:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once(dirname(__FILE__) . '/../b8/Registry.php');
|
|
|
|
require_once(dirname(__FILE__) . '/../b8/Cache.php');
|
|
|
|
|
2016-04-14 19:10:08 +02:00
|
|
|
use b8\Registry, b8\Cache;
|
2016-04-12 19:31:39 +02:00
|
|
|
|
|
|
|
class CacheTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testCreateSingleton()
|
|
|
|
{
|
2016-04-14 19:10:08 +02:00
|
|
|
$cache = Cache::getCache(Cache::TYPE_APC);
|
2016-04-12 19:31:39 +02:00
|
|
|
$this->assertTrue($cache instanceof Cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisableCaching()
|
|
|
|
{
|
2016-04-14 19:10:08 +02:00
|
|
|
Registry::getInstance()->set('DisableCaching', true);
|
2016-04-12 19:31:39 +02:00
|
|
|
|
2016-04-14 19:10:08 +02:00
|
|
|
$cache = Cache::getCache(Cache::TYPE_APC);
|
2016-04-12 19:31:39 +02:00
|
|
|
$this->assertFalse($cache->isEnabled());
|
|
|
|
$this->assertFalse($cache->set('anything', 10));
|
|
|
|
$this->assertTrue(is_null($cache->get('anything')));
|
|
|
|
|
2016-04-14 19:10:08 +02:00
|
|
|
Registry::getInstance()->set('DisableCaching', false);
|
2016-04-12 19:31:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCaching()
|
|
|
|
{
|
2016-04-14 19:10:08 +02:00
|
|
|
$cache = Cache::getCache(Cache::TYPE_APC);
|
2016-04-12 19:31:39 +02:00
|
|
|
|
|
|
|
if($cache->isEnabled())
|
|
|
|
{
|
|
|
|
$this->assertTrue($cache->set('anything', 10));
|
|
|
|
$this->assertTrue($cache->get('anything') == 10);
|
|
|
|
$this->assertTrue(is_null($cache->get('invalid')));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|