public function PhpFileCacheTest::testLifetime in Plug 7
File
- lib/
doctrine/ cache/ tests/ Doctrine/ Tests/ Common/ Cache/ PhpFileCacheTest.php, line 13
Class
- PhpFileCacheTest
- @group DCOM-101
Namespace
Doctrine\Tests\Common\CacheCode
public function testLifetime() {
$cache = $this
->_getCacheDriver();
// Test save
$cache
->save('test_key', 'testing this out', 10);
// Test contains to test that save() worked
$this
->assertTrue($cache
->contains('test_key'));
// Test fetch
$this
->assertEquals('testing this out', $cache
->fetch('test_key'));
// access private methods
$getFilename = new \ReflectionMethod($cache, 'getFilename');
$getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
$getFilename
->setAccessible(true);
$getNamespacedId
->setAccessible(true);
$id = $getNamespacedId
->invoke($cache, 'test_key');
$path = $getFilename
->invoke($cache, $id);
$value = (include $path);
// update lifetime
$value['lifetime'] = $value['lifetime'] - 20;
file_put_contents($path, '<?php return unserialize(' . var_export(serialize($value), true) . ');');
// test expired data
$this
->assertFalse($cache
->contains('test_key'));
$this
->assertFalse($cache
->fetch('test_key'));
}