BaseFileCacheTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use RecursiveDirectoryIterator;
  4. use RecursiveIteratorIterator;
  5. abstract class BaseFileCacheTest extends CacheTest
  6. {
  7. protected $directory;
  8. public function testFlushAllRemovesBalancingDirectories()
  9. {
  10. $cache = $this->_getCacheDriver();
  11. $this->assertTrue($cache->save('key1', 1));
  12. $this->assertTrue($cache->save('key2', 2));
  13. $this->assertTrue($cache->flushAll());
  14. $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
  15. $this->assertCount(0, $iterator);
  16. }
  17. protected function setUp()
  18. {
  19. do {
  20. $this->directory = sys_get_temp_dir() . '/doctrine_cache_'. uniqid();
  21. } while (file_exists($this->directory));
  22. }
  23. protected function tearDown()
  24. {
  25. if ( ! is_dir($this->directory)) {
  26. return;
  27. }
  28. $iterator = new RecursiveDirectoryIterator($this->directory);
  29. foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
  30. if ($file->isFile()) {
  31. @unlink($file->getRealPath());
  32. } elseif ($file->isDir()) {
  33. @rmdir($file->getRealPath());
  34. }
  35. }
  36. @rmdir($this->directory);
  37. }
  38. protected function isSharedStorage()
  39. {
  40. return false;
  41. }
  42. }