TestCase.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class Twig_Tests_TestCase extends PHPUnit_Framework_TestCase
  3. {
  4. protected $tmpDir;
  5. public function getTempDir()
  6. {
  7. return $this->tmpDir;
  8. }
  9. function setUp()
  10. {
  11. $this->tmpDir = sys_get_temp_dir().'/TwigTests';
  12. if (!file_exists($this->tmpDir)) {
  13. @mkdir($this->tmpDir, 0777, true);;
  14. }
  15. if (!is_writable($this->tmpDir)) {
  16. $this->markTestSkipped(sprintf('Unable to run the tests as "%s" is not writable.', $this->tmpDir));
  17. }
  18. parent::setUp();
  19. }
  20. function tearDown()
  21. {
  22. $this->removeDir($this->tmpDir);
  23. parent::tearDown();
  24. }
  25. private function removeDir($target)
  26. {
  27. $fp = opendir($target);
  28. while (false !== $file = readdir($fp)) {
  29. if (in_array($file, array('.', '..'))) {
  30. continue;
  31. }
  32. if (is_dir($target.'/'.$file)) {
  33. self::removeDir($target.'/'.$file);
  34. } else {
  35. unlink($target.'/'.$file);
  36. }
  37. }
  38. closedir($fp);
  39. rmdir($target);
  40. }
  41. }