From e0d4e4b1fa4190518ece1bae1298396c0c23e66b Mon Sep 17 00:00:00 2001 From: uwetews Date: Tue, 9 Feb 2016 01:32:50 +0100 Subject: [PATCH] new core functions --- tests/CleanUp.php | 18 +++++++++++---- tests/PHPUnit_Smarty.php | 50 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/tests/CleanUp.php b/tests/CleanUp.php index 05af017c..3fe84a77 100644 --- a/tests/CleanUp.php +++ b/tests/CleanUp.php @@ -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'); + } } } diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index 825e957b..70d15a3e 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -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 *