From b887f18acfd650b511e937d34acacd73fd6471bc Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 30 Dec 2015 21:14:22 +0100 Subject: [PATCH] update configuration of disabled resource tests --- tests/Bootstrap.php | 3 +- tests/PHPUnit_Smarty.php | 27 ++++---- .../Apc/CacheResourceCustomApcTest.php | 43 ++++++------- .../CacheResourceCustomMemcacheTest.php | 60 +++++++++--------- .../Mysql/CacheResourceCustomMysqlTest.php | 54 ++++++++-------- .../PDO/CacheResourceCustomPDOTest.php | 62 ++++++++++--------- .../CacheResourceCustomPDOGzipTest.php | 58 +++++++++-------- .../CacheResourceCustomRegisteredTest.php | 58 ++++++++--------- 8 files changed, 190 insertions(+), 175 deletions(-) diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index baf22860..13756fa9 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -6,6 +6,7 @@ /* * Smarty PHPUnit Bootstrap */ +include_once __DIR__ . '/Config.php'; // Locate Autoloader or SmartyBC class and load it if (is_file(__DIR__ . '/../smarty/libs/Autoloader.php')) { require_once __DIR__ . '/../smarty/libs/Autoloader.php'; @@ -22,7 +23,7 @@ if (is_file(__DIR__ . '/../smarty/libs/Autoloader.php')) { } if (!defined('SMARTY_COMPOSER_INSTALL')) { foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', - __DIR__ . '/vendor/autoload.php') as $file) { + __DIR__ . '/vendor/autoload.php') as $file) { if (file_exists($file)) { define('SMARTY_COMPOSER_INSTALL', $file); break; diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index aff2ab6e..3dcc73f2 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -4,8 +4,6 @@ * */ -include_once __DIR__ . '/Config.php'; - /** * Smarty Test Case Fixture */ @@ -106,7 +104,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'); } /** @@ -129,10 +127,10 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase mkdir($dir . '/configs'); } if (individualFolders != 'true') { - if (!isset($s_dir[$dir])) { + if (!isset($s_dir[ $dir ])) { $this->cleanDir($dir . '/templates_c'); $this->cleanDir($dir . '/cache'); - $s_dir[$dir] = true; + $s_dir[ $dir ] = true; } $dir = __DIR__; } @@ -351,7 +349,8 @@ KEY `expire` (`expire`) case 'file': case 'filetest': if ($tpl instanceof Smarty) { - return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) . $this->smarty->_joined_template_dir); + return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) . + $this->smarty->_joined_template_dir); } return sha1($tpl->source->filepath . $this->smarty->_joined_template_dir); case 'mysqltest': @@ -375,7 +374,7 @@ KEY `expire` (`expire`) */ public function normalizePath($path) { - if ($path[0] == '.') { + if ($path[ 0 ] == '.') { $path = getcwd() . DS . $path; } $path = preg_replace('#[\\\/]+([.][\\\/]+)*#', DS, $path); @@ -532,15 +531,15 @@ KEY `expire` (`expire`) $uid = $this->buildUid($tpl, $sp, $name, $type); $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null; - return sha1($uid . $_cache_id . $_compile_id); + return sha1($uid . $_cache_id . $_compile_id); case 'memcachetest': case 'acp': - $sp = $this->buildSourcePath($tpl, $name, $type, $dir); - $uid = $this->buildUid($tpl, $sp, $name, $type); - $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; - $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null; - return sha1($uid) . '#' . preg_replace('#[^\w\|]+#S', '_', $tpl->template_resource) . '#' . - $_cache_id . '#' . $_compile_id; + $sp = $this->buildSourcePath($tpl, $name, $type, $dir); + $uid = $this->buildUid($tpl, $sp, $name, $type); + $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; + $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null; + return sha1($uid) . '#' . preg_replace('#[^\w\|]+#S', '_', $tpl->template_resource) . '#' . $_cache_id . + '#' . $_compile_id; default: throw new Exception("Unhandled cache resource type '{$cacheType}'"); diff --git a/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php b/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php index 35e3aa54..4f957ae6 100644 --- a/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php +++ b/tests/UnitTests/CacheResourceTests/Apc/CacheResourceCustomApcTest.php @@ -5,31 +5,32 @@ * @package PHPunit * @author Uwe Tews */ +if (ApcCacheEnable == true) { + include_once __DIR__ . '/../Memcache/CacheResourceCustomMemcacheTest.php'; -include_once __DIR__ . '/../Memcache/CacheResourceCustomMemcacheTest.php'; - -/** - * class for cache resource file tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest -{ - public function setUp() + /** + * class for cache resource file tests + * + * @runTestsInSeparateProcess + * @preserveGlobalState disabled + * @backupStaticAttributes enabled + */ + class CacheResourceCustomApcTest extends CacheResourceCustomMemcacheTest { - if (ApcCacheEnable != true) { - $this->markTestSkipped('Apc tests are disabled'); - } else { - if (!function_exists('apc_cache_info') || ini_get('apc.enable_cli')) { - $this->markTestSkipped('APC cache not available'); + public function setUp() + { + if (ApcCacheEnable != true) { + $this->markTestSkipped('Apc tests are disabled'); + } else { + if (!function_exists('apc_cache_info') || ini_get('apc.enable_cli')) { + $this->markTestSkipped('APC cache not available'); + } } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->setCachingType('apc'); + $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('apc'); - $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); } } diff --git a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php index 32c59ee8..9a9433f1 100644 --- a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php +++ b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php @@ -5,44 +5,46 @@ * @package PHPunit * @author Uwe Tews */ +if (MemCacheEnable == true) { -include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; + include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; -/** - * class for cache resource memcache tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon -{ /** - * Sets up the fixture - * This method is called before a test is executed. + * class for cache resource memcache tests * + * @runTestsInSeparateProcess + * @preserveGlobalState disabled + * @backupStaticAttributes enabled */ - public function setUp() + class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon { - if (MemCacheEnable != true) { - $this->markTestSkipped('Memcache tests are disabled'); - } else { - if (!class_exists('Memcache')) { - $this->markTestSkipped('Memcache not available'); + /** + * Sets up the fixture + * This method is called before a test is executed. + * + */ + public function setUp() + { + if (MemCacheEnable != true) { + $this->markTestSkipped('Memcache tests are disabled'); + } else { + if (!class_exists('Memcache')) { + $this->markTestSkipped('Memcache not available'); + } } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->setCachingType('memcachetest'); } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('memcachetest'); - } - public function testInit() - { - $this->cleanDirs(); - } + public function testInit() + { + $this->cleanDirs(); + } - protected function doClearCacheAssertion($a, $b) - { - $this->assertEquals(- 1, $b); + protected function doClearCacheAssertion($a, $b) + { + $this->assertEquals(- 1, $b); + } } } diff --git a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php index cfbe4eaa..0b500d1c 100644 --- a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php +++ b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php @@ -5,36 +5,38 @@ * @package PHPunit * @author Uwe Tews */ +if (MysqlCacheEnable == true) { -include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; + include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; -/** - * class for cache resource file tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CacheResourceCustomMysqlTest extends CacheResourceTestCommon -{ - - public function setUp() + /** + * class for cache resource file tests + * + * @runTestsInSeparateProcess + * @preserveGlobalState disabled + * @backupStaticAttributes enabled + */ + class CacheResourceCustomMysqlTest extends CacheResourceTestCommon { - if (MysqlCacheEnable != true) { - $this->markTestSkipped('mysql tests are disabled'); - } - if (self::$init) { - $this->getConnection(); - } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('mysqltest'); - } - public function testInit() - { - $this->cleanDirs(); - $this->initMysqlCache(); + public function setUp() + { + if (MysqlCacheEnable != true) { + $this->markTestSkipped('mysql tests are disabled'); + } + if (self::$init) { + $this->getConnection(); + } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->setCachingType('mysqltest'); + } + + public function testInit() + { + $this->cleanDirs(); + $this->initMysqlCache(); + } } } diff --git a/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php b/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php index 9dcdfc5c..fc9d0afd 100644 --- a/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php +++ b/tests/UnitTests/CacheResourceTests/PDO/CacheResourceCustomPDOTest.php @@ -5,39 +5,43 @@ * @package PHPunit * @author Uwe Tews */ +if (PdoCacheEnable == true) { -include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; + include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; -/** - * class for cache resource file tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CacheResourceCustomPDOTest extends CacheResourceTestCommon -{ - - public function setUp($dir = null, $clear = true) + /** + * class for cache resource file tests + * + * @runTestsInSeparateProcess + * @preserveGlobalState disabled + * @backupStaticAttributes enabled + */ + class CacheResourceCustomPDOTest extends CacheResourceTestCommon { - if (PdoCacheEnable != true) { - $this->markTestSkipped('mysql Pdo tests are disabled'); - } - if (self::$init) { - $this->getConnection(); - } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('pdo'); - $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); - $this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdotest'), 'loadPlugin() could not load PDO cache resource'); - $this->smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdotest($this->getPDO(), 'output_cache')); - } - public function testInit() - { - $this->cleanDirs(); - $this->initMysqlCache(); + public function setUp($dir = null, $clear = true) + { + if (PdoCacheEnable != true) { + $this->markTestSkipped('mysql Pdo tests are disabled'); + } + if (self::$init) { + $this->getConnection(); + } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->setCachingType('pdo'); + $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); + $this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdotest'), + 'loadPlugin() could not load PDO cache resource'); + $this->smarty->registerCacheResource('pdo', + new Smarty_CacheResource_Pdotest($this->getPDO(), 'output_cache')); + } + + public function testInit() + { + $this->cleanDirs(); + $this->initMysqlCache(); + } } } diff --git a/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php b/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php index d3de1742..5df30e25 100644 --- a/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php +++ b/tests/UnitTests/CacheResourceTests/PDOgzip/CacheResourceCustomPDOGzipTest.php @@ -5,37 +5,41 @@ * @package PHPunit * @author Uwe Tews */ +if (PdoGzipCacheEnable == true) { -include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; + include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; -/** - * class for cache resource file tests - * - * @backupStaticAttributes enabled - */ -class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon -{ - - public function setUp($dir = null, $clear = true) + /** + * class for cache resource file tests + * + * @backupStaticAttributes enabled + */ + class CacheResourceCustomPDOGzipTest extends CacheResourceTestCommon { - if (PdoGzipCacheEnable != true) { - $this->markTestSkipped('mysql Pdo Gzip tests are disabled'); - } - if (self::$init) { - $this->getConnection(); - } - $this->setUpSmarty(__DIR__); - parent::setUp(); - $this->smarty->setCachingType('pdo'); - $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); - $this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdo_Gziptest'), 'loadPlugin() could not load PDOGzip cache resource'); - $this->smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo_Gziptest($this->getPDO(), 'output_cache')); - } - public function testInit() - { - $this->cleanDirs(); - $this->initMysqlCache(); + public function setUp($dir = null, $clear = true) + { + if (PdoGzipCacheEnable != true) { + $this->markTestSkipped('mysql Pdo Gzip tests are disabled'); + } + if (self::$init) { + $this->getConnection(); + } + $this->setUpSmarty(__DIR__); + parent::setUp(); + $this->smarty->setCachingType('pdo'); + $this->smarty->addPluginsDir(SMARTY_DIR . '../demo/plugins/'); + $this->assertTrue(false !== $this->smarty->loadPlugin('Smarty_CacheResource_Pdo_Gziptest'), + 'loadPlugin() could not load PDOGzip cache resource'); + $this->smarty->registerCacheResource('pdo', new Smarty_CacheResource_Pdo_Gziptest($this->getPDO(), + 'output_cache')); + } + + public function testInit() + { + $this->cleanDirs(); + $this->initMysqlCache(); + } } } diff --git a/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php b/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php index 27dc646d..8bd34941 100644 --- a/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php +++ b/tests/UnitTests/CacheResourceTests/Registered/CacheResourceCustomRegisteredTest.php @@ -5,38 +5,40 @@ * @package PHPunit * @author Uwe Tews */ -include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; +if (MysqlCacheEnable == true) { + include_once __DIR__ . '/../_shared/CacheResourceTestCommon.php'; -/** - * class for cache resource file tests - * - * @runTestsInSeparateProcess - * @preserveGlobalState disabled - * @backupStaticAttributes enabled - */ -class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon -{ - public function setUp() + /** + * class for cache resource file tests + * + * @runTestsInSeparateProcess + * @preserveGlobalState disabled + * @backupStaticAttributes enabled + */ + class CacheResourceCustomRegisteredTest extends CacheResourceTestCommon { - if (MysqlCacheEnable != true) { - $this->markTestSkipped('mysql tests are disabled'); + public function setUp() + { + if (MysqlCacheEnable != true) { + $this->markTestSkipped('mysql tests are disabled'); + } + if (self::$init) { + $this->getConnection(); + } + $this->setUpSmarty(__DIR__); + parent::setUp(); + if (!class_exists('Smarty_CacheResource_Mysqltest', false)) { + require_once(__DIR__ . "/../_shared/PHPunitplugins/cacheresource.mysqltest.php"); + } + $this->smarty->setCachingType('foobar'); + $this->smarty->registerCacheResource('foobar', new Smarty_CacheResource_Mysqltest()); } - if (self::$init) { - $this->getConnection(); - } - $this->setUpSmarty(__DIR__); - parent::setUp(); - if (!class_exists('Smarty_CacheResource_Mysqltest', false)) { - require_once(__DIR__ . "/../_shared/PHPunitplugins/cacheresource.mysqltest.php"); - } - $this->smarty->setCachingType('foobar'); - $this->smarty->registerCacheResource('foobar', new Smarty_CacheResource_Mysqltest()); - } - public function testInit() - { - $this->cleanDirs(); - $this->initMysqlCache(); + public function testInit() + { + $this->cleanDirs(); + $this->initMysqlCache(); + } } }