From 3395f4221ed9a4993fc776846bdcd91f41f3b49a Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 25 Sep 2010 23:04:49 -0400 Subject: [PATCH] Adding Inflector::reset(). This makes non-isolated test runs possible. Adding inflector to the libs suite. --- cake/libs/inflector.php | 28 ++++++++++++++++++++++++ cake/tests/cases/libs/all_libs.test.php | 1 + cake/tests/cases/libs/inflector.test.php | 10 +++++---- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 3b1efd0cc..9221c820b 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -234,6 +234,13 @@ class Inflector { */ protected static $_cache = array(); +/** + * The initial state of Inflector so reset() works. + * + * @var array + */ + protected static $_initialState = array(); + /** * Cache inflected values, and return if already available * @@ -255,6 +262,24 @@ class Inflector { return self::$_cache[$type][$key]; } +/** + * Clears Inflectors inflected value caches. And resets the inflection + * rules to the initial values. + * + * @return void + */ + public static function reset() { + if (empty(self::$_initialState)) { + self::$_initialState = get_class_vars('Inflector'); + return; + } + foreach (self::$_initialState as $key => $val) { + if ($key != '_initialState') { + self::${$key} = $val; + } + } + } + /** * Adds custom inflection $rules, of either 'plural', 'singular' or 'transliteration' $type. * @@ -540,3 +565,6 @@ class Inflector { return preg_replace(array_keys($map), array_values($map), $string); } } + +// Store the initial state +Inflector::reset(); \ No newline at end of file diff --git a/cake/tests/cases/libs/all_libs.test.php b/cake/tests/cases/libs/all_libs.test.php index 32a196953..3d334d72b 100644 --- a/cake/tests/cases/libs/all_libs.test.php +++ b/cake/tests/cases/libs/all_libs.test.php @@ -42,6 +42,7 @@ class AllLibsTest extends PHPUnit_Framework_TestSuite { $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'error_handler.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'file.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'folder.test.php'); + $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'inflector.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'log' . DS . 'file_log.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_log.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php'); diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 4dab49f49..edf434e9b 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -35,12 +35,14 @@ App::import('Core', 'Inflector'); class InflectorTest extends CakeTestCase { /** - * Inflector property + * teardown * - * @var mixed null - * @access public + * @return void */ - public $Inflector = null; + function tearDown() { + parent::tearDown(); + Inflector::reset(); + } /** * testInflectingSingulars method