From 3d9288dc8e966ff425651f775f35913fe809cec8 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 08:23:04 -0700 Subject: [PATCH] Extract duplicated tmpdir code into base test case --- .../Test/Cache/FilesystemCacheTest.php | 36 +------------- test/Mustache/Test/EngineTest.php | 37 +-------------- test/Mustache/Test/FunctionalTestCase.php | 47 +++++++++++++++++++ 3 files changed, 49 insertions(+), 71 deletions(-) create mode 100644 test/Mustache/Test/FunctionalTestCase.php diff --git a/test/Mustache/Test/Cache/FilesystemCacheTest.php b/test/Mustache/Test/Cache/FilesystemCacheTest.php index e19c33b..5bfb18c 100644 --- a/test/Mustache/Test/Cache/FilesystemCacheTest.php +++ b/test/Mustache/Test/Cache/FilesystemCacheTest.php @@ -12,18 +12,8 @@ /** * @group functional */ -class Mustache_Test_Cache_FilesystemCacheTest extends PHPUnit_Framework_TestCase +class Mustache_Test_Cache_FilesystemCacheTest extends Mustache_Test_FunctionalTestCase { - private static $tempDir; - - public static function setUpBeforeClass() - { - self::$tempDir = sys_get_temp_dir() . '/mustache_test'; - if (file_exists(self::$tempDir)) { - self::rmdir(self::$tempDir); - } - } - public function testCacheGetNone() { $key = 'some key'; @@ -43,28 +33,4 @@ class Mustache_Test_Cache_FilesystemCacheTest extends PHPUnit_Framework_TestCase $this->assertTrue($loaded); } - - /** - * @param string $path - */ - private static function rmdir($path) - { - $path = rtrim($path, '/').'/'; - $handle = opendir($path); - while (($file = readdir($handle)) !== false) { - if ($file == '.' || $file == '..') { - continue; - } - - $fullpath = $path.$file; - if (is_dir($fullpath)) { - self::rmdir($fullpath); - } else { - unlink($fullpath); - } - } - - closedir($handle); - rmdir($path); - } } diff --git a/test/Mustache/Test/EngineTest.php b/test/Mustache/Test/EngineTest.php index af3fe1e..faeed29 100644 --- a/test/Mustache/Test/EngineTest.php +++ b/test/Mustache/Test/EngineTest.php @@ -12,19 +12,8 @@ /** * @group unit */ -class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase +class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase { - - private static $tempDir; - - public static function setUpBeforeClass() - { - self::$tempDir = sys_get_temp_dir() . '/mustache_test'; - if (file_exists(self::$tempDir)) { - self::rmdir(self::$tempDir); - } - } - public function testConstructor() { $logger = new Mustache_Logger_StreamLogger(tmpfile()); @@ -348,30 +337,6 @@ class Mustache_Test_EngineTest extends PHPUnit_Framework_TestCase $this->assertContains("DEBUG: Instantiating template: ", $log); $this->assertContains("WARNING: Partial not found: \"bar\"", $log); } - - /** - * @param string $path - */ - private static function rmdir($path) - { - $path = rtrim($path, '/').'/'; - $handle = opendir($path); - while (($file = readdir($handle)) !== false) { - if ($file == '.' || $file == '..') { - continue; - } - - $fullpath = $path.$file; - if (is_dir($fullpath)) { - self::rmdir($fullpath); - } else { - unlink($fullpath); - } - } - - closedir($handle); - rmdir($path); - } } class MustacheStub extends Mustache_Engine diff --git a/test/Mustache/Test/FunctionalTestCase.php b/test/Mustache/Test/FunctionalTestCase.php new file mode 100644 index 0000000..73cfa9c --- /dev/null +++ b/test/Mustache/Test/FunctionalTestCase.php @@ -0,0 +1,47 @@ +