| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- use Ark\Filecache\FileCache;
- class BaseTest extends PHPUnit_Framework_TestCase {
- protected $cache;
- public function setUp() {
- $this->cache = new FileCache([
- 'root' => __DIR__ . '/cache',
- ]);
- }
- public function tearDown() {
- $this->cache->clear();
- // test clear twice
- $this->cache->clear();
- }
- public function testSet() {
- $key = __FUNCTION__;
- $value = 'hello world';
- $this->cache->set($key, $value);
- $this->assertEquals($this->cache->get($key), $value);
- }
- public function testTTL() {
- $key = __FUNCTION__;
- $value = 'hello world';
- $this->cache->set($key, $value, array(
- 'ttl' => 2,
- ));
- $this->assertEquals($this->cache->get($key), $value);
- sleep(3);
- $this->assertEquals($this->cache->get($key), false);
- }
- public function testCompress() {
- $key = __FUNCTION__;
- $value = 'hello world';
- $this->cache->set($key, $value, array(
- 'compress' => true
- ));
- $meta = $this->cache->getMeta($key);
- $this->assertEquals($meta['compress'], '1');
- $this->assertEquals($this->cache->get($key), $value);
- }
- public function testDelete()
- {
- $key = __FUNCTION__;
- $value = 'hello world';
- $this->cache->set($key, $value);
- $this->cache->delete($key);
- $this->assertEquals($this->cache->get($key), false);
- }
- }
|