FunctionalTestCase.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2017 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. abstract class Mustache_Test_FunctionalTestCase extends PHPUnit_Framework_TestCase
  11. {
  12. protected static $tempDir;
  13. public static function setUpBeforeClass()
  14. {
  15. self::$tempDir = sys_get_temp_dir() . '/mustache_test';
  16. if (file_exists(self::$tempDir)) {
  17. self::rmdir(self::$tempDir);
  18. }
  19. }
  20. /**
  21. * @param string $path
  22. */
  23. protected static function rmdir($path)
  24. {
  25. $path = rtrim($path, '/') . '/';
  26. $handle = opendir($path);
  27. while (($file = readdir($handle)) !== false) {
  28. if ($file === '.' || $file === '..') {
  29. continue;
  30. }
  31. $fullpath = $path . $file;
  32. if (is_dir($fullpath)) {
  33. self::rmdir($fullpath);
  34. } else {
  35. unlink($fullpath);
  36. }
  37. }
  38. closedir($handle);
  39. rmdir($path);
  40. }
  41. }