FilesystemCacheTest.php in Zircon Profile 8.0
File
vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php
View source
<?php
namespace Doctrine\Tests\Common\Cache;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\FilesystemCache;
class FilesystemCacheTest extends BaseFileCacheTest {
public function testLifetime() {
$cache = $this
->_getCacheDriver();
$cache
->save('test_key', 'testing this out', 10);
$this
->assertTrue($cache
->contains('test_key'));
$this
->assertEquals('testing this out', $cache
->fetch('test_key'));
$getFilename = new \ReflectionMethod($cache, 'getFilename');
$getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
$getFilename
->setAccessible(true);
$getNamespacedId
->setAccessible(true);
$id = $getNamespacedId
->invoke($cache, 'test_key');
$filename = $getFilename
->invoke($cache, $id);
$data = '';
$lifetime = 0;
$resource = fopen($filename, "r");
if (false !== ($line = fgets($resource))) {
$lifetime = (int) $line;
}
while (false !== ($line = fgets($resource))) {
$data .= $line;
}
$this
->assertNotEquals(0, $lifetime, "previous lifetime could not be loaded");
$lifetime = $lifetime - 20;
file_put_contents($filename, $lifetime . PHP_EOL . $data);
$this
->assertFalse($cache
->contains('test_key'));
$this
->assertFalse($cache
->fetch('test_key'));
}
public function testGetStats() {
$cache = $this
->_getCacheDriver();
$stats = $cache
->getStats();
$this
->assertNull($stats[Cache::STATS_HITS]);
$this
->assertNull($stats[Cache::STATS_MISSES]);
$this
->assertNull($stats[Cache::STATS_UPTIME]);
$this
->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]);
$this
->assertGreaterThan(0, $stats[Cache::STATS_MEMORY_AVAILABLE]);
}
protected function _getCacheDriver() {
return new FilesystemCache($this->directory);
}
}