Extract duplicated tmpdir code into base test case
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user