Adding Inflector::reset(). This makes non-isolated test runs possible. Adding inflector to the libs suite.

This commit is contained in:
mark_story 2010-09-25 23:04:49 -04:00
parent 63d23df77a
commit 3395f4221e
3 changed files with 35 additions and 4 deletions

View file

@ -234,6 +234,13 @@ class Inflector {
*/ */
protected static $_cache = array(); 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 * Cache inflected values, and return if already available
* *
@ -255,6 +262,24 @@ class Inflector {
return self::$_cache[$type][$key]; 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. * 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); return preg_replace(array_keys($map), array_values($map), $string);
} }
} }
// Store the initial state
Inflector::reset();

View file

@ -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 . 'error_handler.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'file.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 . '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 . '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 . 'cake_log.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php'); $suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php');

View file

@ -35,12 +35,14 @@ App::import('Core', 'Inflector');
class InflectorTest extends CakeTestCase { class InflectorTest extends CakeTestCase {
/** /**
* Inflector property * teardown
* *
* @var mixed null * @return void
* @access public
*/ */
public $Inflector = null; function tearDown() {
parent::tearDown();
Inflector::reset();
}
/** /**
* testInflectingSingulars method * testInflectingSingulars method