SafeLocalTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Gaufrette\Functional\Adapter;
  3. use Gaufrette\Filesystem;
  4. use Gaufrette\Adapter\SafeLocal;
  5. class SafeLocalTest extends FunctionalTestCase
  6. {
  7. public function setUp()
  8. {
  9. if (!file_exists($this->getDirectory())) {
  10. mkdir($this->getDirectory());
  11. }
  12. $this->filesystem = new Filesystem(new SafeLocal($this->getDirectory()));
  13. }
  14. public function tearDown()
  15. {
  16. $this->filesystem = null;
  17. if (file_exists($this->getDirectory())) {
  18. $iterator = new \RecursiveIteratorIterator(
  19. new \RecursiveDirectoryIterator(
  20. $this->getDirectory(),
  21. \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
  22. )
  23. );
  24. foreach ($iterator as $item) {
  25. if ($item->isDir()) {
  26. rmdir(strval($item));
  27. } else {
  28. unlink(strval($item));
  29. }
  30. }
  31. }
  32. }
  33. private function getDirectory()
  34. {
  35. return sprintf('%s/filesystem', __DIR__);
  36. }
  37. }