Extract duplicated tmpdir code into base test case

This commit is contained in:
Justin Hileman
2014-03-25 08:23:04 -07:00
parent 84a4ff5b16
commit 3d9288dc8e
3 changed files with 49 additions and 71 deletions
@@ -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);
}
}
+1 -36
View File
@@ -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
+47
View File
@@ -0,0 +1,47 @@
<?php
/*
* This file is part of Mustache.php.
*
* (c) 2010-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
abstract class Mustache_Test_FunctionalTestCase extends PHPUnit_Framework_TestCase
{
protected static $tempDir;
public static function setUpBeforeClass()
{
self::$tempDir = sys_get_temp_dir() . '/mustache_test';
if (file_exists(self::$tempDir)) {
self::rmdir(self::$tempDir);
}
}
/**
* @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);
}
}