php-censor/tests/B8Framework/CacheTest.php

40 lines
898 B
PHP
Raw Normal View History

2016-04-12 19:31:39 +02:00
<?php
2016-04-17 08:34:12 +02:00
namespace Tests\b8;
2016-04-12 19:31:39 +02:00
2016-04-17 08:34:12 +02:00
use b8\Config, 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-17 08:34:12 +02:00
$config = new Config();
Config::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-17 08:34:12 +02:00
Config::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')));
}
}
}