new core functions

This commit is contained in:
uwetews
2016-02-09 01:32:50 +01:00
parent c48e16c5fe
commit e0d4e4b1fa
2 changed files with 61 additions and 7 deletions

View File

@@ -3,19 +3,29 @@
* This file is part of the Smarty PHPUnit tests.
*
*/
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__), FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__), FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST) as $path) {
$p = $path->getPathname();
if ((strpos($p, '\coverage') !== false) || ((strpos($p, '\templates_c') === false) && (strpos($p, '\cache') === false))) {
if ((strpos($p, '\coverage') !== false) ||
((strpos($p, '\templates_c') === false) && (strpos($p, '\cache\\') === false) &&
(strpos($p, '\templates_tmp') === false))
) {
continue;
}
$p = $path->getPathname();
$i = 1;
//$path->isDir() && !$path->isLink() ? rmdir($path->getPathname()) : unlink($path->getPathname());
if ($path->isDir() && !$path->isLink()) {
touch($path->getPathname() . '/dummy.txt');
if (strpos($p, '\templates_tmp') !== false) {
rmdir($path->getPathname());
} else {
touch($path->getPathname() . '/dummy.txt');
}
} else {
unlink($path->getPathname());
touch($path->getPath() . '/dummy.txt');
if (strpos($p, '\templates_tmp') === false) {
touch($path->getPath() . '/dummy.txt');
}
}
}

View File

@@ -44,6 +44,13 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
*/
public static $init = true;
/**
* Count test number
*
* @var bool
*/
public static $testNumber = 0;
/**
* Configuration data from config.xml
*
@@ -70,7 +77,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
*
* @var array
*/
protected $backupStaticAttributesBlacklist = array('PHPUnit_Smarty' => array('config', 'pdo', 'init'),);
protected $backupStaticAttributesBlacklist = array('PHPUnit_Smarty' => array('config', 'pdo', 'init', 'testNumver'),);
/**
* This method is called before the first test of this test class is run.
@@ -89,6 +96,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
public static function tearDownAfterClass()
{
//self::$pdo = null;
self::$testNumber = 0;
}
/**
@@ -104,7 +112,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
define('individualFolders', true);
}
parent::__construct($name, $data, $dataName);
$this->backupStaticAttributesBlacklist[ get_class($this) ] = array('init', 'config', 'pdo');
$this->backupStaticAttributesBlacklist[ get_class($this) ] = array('init', 'config', 'pdo', 'testNumber');
}
/**
@@ -130,7 +138,10 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
if (!isset($s_dir[ $dir ])) {
$this->cleanDir($dir . '/templates_c');
$this->cleanDir($dir . '/cache');
$s_dir[ $dir ] = true;
if (is_dir($dir . '/templates_tmp')) {
$this->cleanDir($dir . '/templates_tmp');
}
$s_dir[ $dir ] = true;
}
$dir = dirname(__FILE__);
}
@@ -230,6 +241,23 @@ KEY `expire` (`expire`)
{
$this->cleanCompileDir();
$this->cleanCacheDir();
if (is_dir(self::$cwd . '/templates_tmp')) {
$this->cleanDir(self::$cwd . '/templates_tmp');
}
}
/**
* Make temporary template file
*
*/
public function makeTemplateFile($name, $code)
{
if (!is_dir(self::$cwd . '/templates_tmp')) {
mkdir(self::$cwd . '/templates_tmp');
chmod(self::$cwd . '/templates_tmp', 0775);
}
$fileName = self::$cwd . '/templates_tmp/' . "{$name}";
file_put_contents($fileName, $code);
}
/**
@@ -309,6 +337,22 @@ KEY `expire` (`expire`)
}
}
/**
* Remove all spaces
*
* @param string $in
*
* @return mixed
*/
public function strip($in)
{
if (is_string($in)) {
return preg_replace('/\s/', '', $in);
} else {
return $in;
}
}
/**
* Return source path
*