You are here

class FilesystemCacheTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php \Doctrine\Tests\Common\Cache\FilesystemCacheTest

@group DCOM-101

Hierarchy

Expanded class hierarchy of FilesystemCacheTest

File

vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/FilesystemCacheTest.php, line 11

Namespace

Doctrine\Tests\Common\Cache
View source
class FilesystemCacheTest extends BaseFileCacheTest {
  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');
    $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");

    // update lifetime
    $lifetime = $lifetime - 20;
    file_put_contents($filename, $lifetime . PHP_EOL . $data);

    // test expired 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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseFileCacheTest::$directory protected property
BaseFileCacheTest::isSharedStorage protected function Return whether multiple cache providers share the same storage. Overrides CacheTest::isSharedStorage
BaseFileCacheTest::setUp public function
BaseFileCacheTest::tearDown public function
CacheTest::falseCastedValuesProvider public function The following values get converted to FALSE if you cast them to a boolean.
CacheTest::provideCrudValues public function
CacheTest::testBasicCrudOperations public function @dataProvider provideCrudValues
CacheTest::testCachedObject public function Check to see that objects are correctly serialized and unserialized by the cache provider. 1
CacheTest::testDeleteAll public function
CacheTest::testDeleteAllAndNamespaceVersioningBetweenCaches public function
CacheTest::testDeleteAllNamespace public function
CacheTest::testFalseCastedValues public function Check to see that, even if the user saves a value that can be interpreted as false, the cache adapter will still recognize its existence there. 2
CacheTest::testFetchMissShouldReturnFalse public function
CacheTest::testFetchMulti public function
CacheTest::testFetchMultipleObjects public function Check to see that objects fetched via fetchMultiple are properly unserialized 1
CacheTest::testFetchMultiWillFilterNonRequestedKeys public function
CacheTest::testFlushAll public function
CacheTest::testFlushAllAndNamespaceVersioningBetweenCaches public function
CacheTest::testNamespace public function
FilesystemCacheTest::testGetStats public function @group DCOM-43 Overrides CacheTest::testGetStats
FilesystemCacheTest::testLifetime public function
FilesystemCacheTest::_getCacheDriver protected function Overrides CacheTest::_getCacheDriver