mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding Inflector::reset(). This makes non-isolated test runs possible. Adding inflector to the libs suite.
This commit is contained in:
parent
63d23df77a
commit
3395f4221e
3 changed files with 35 additions and 4 deletions
|
@ -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();
|
|
@ -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');
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue