Skip to content

Commit

Permalink
Changing how merged rules are cleared so it doesn't generated notice …
Browse files Browse the repository at this point in the history
…errors in PHP4. Test added. Fixes #762
  • Loading branch information
markstory committed Jun 2, 2010
1 parent 8d8fce4 commit 7682c58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
5 changes: 4 additions & 1 deletion cake/libs/inflector.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ function rules($type, $rules, $reset = false) {
} else { } else {
$_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]); $_this->{$var}[$rule] = array_merge($pattern, $_this->{$var}[$rule]);
} }
unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)], $_this->{$var}['merged'][$rule]); unset($rules[$rule], $_this->{$var}['cache' . ucfirst($rule)]);
if (isset($_this->{$var}['merged'][$rule])) {
unset($_this->{$var}['merged'][$rule]);
}
if ($type === 'plural') { if ($type === 'plural') {
$_this->_pluralized = $_this->_tableize = array(); $_this->_pluralized = $_this->_tableize = array();
} elseif ($type === 'singular') { } elseif ($type === 'singular') {
Expand Down
35 changes: 15 additions & 20 deletions cake/tests/cases/libs/inflector.test.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,24 +42,15 @@ class InflectorTest extends CakeTestCase {
*/ */
var $Inflector = null; var $Inflector = null;


/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
$this->Inflector = Inflector::getInstance();
}

/** /**
* testInstantiation method * testInstantiation method
* *
* @access public * @access public
* @return void * @return void
*/ */
function testInstantiation() { function testInstantiation() {
$this->assertEqual(Inflector::getInstance(), $this->Inflector); $Inflector =& Inflector::getInstance();
$this->assertEqual(Inflector::getInstance(), $Inflector);
} }


/** /**
Expand Down Expand Up @@ -339,6 +330,19 @@ function testHumanization() {
$this->assertEqual(Inflector::humanize('file_systems'), 'File Systems'); $this->assertEqual(Inflector::humanize('file_systems'), 'File Systems');
} }


/**
* This test if run in isolation should not cause errors in PHP4.
*
* @return void
*/
function testRulesNoErrorPHP4() {
Inflector::rules('plural', array(
'rules' => array(),
'irregular' => array(),
'uninflected' => array('pays')
));
}

/** /**
* testCustomPluralRule method * testCustomPluralRule method
* *
Expand Down Expand Up @@ -455,13 +459,4 @@ function testCustomRuleWithReset() {
$this->assertEqual(Inflector::singularize('Atlas'), 'Atlas'); $this->assertEqual(Inflector::singularize('Atlas'), 'Atlas');
} }


/**
* tearDown method
*
* @access public
* @return void
*/
function tearDown() {
unset($this->Inflector);
}
} }

0 comments on commit 7682c58

Please sign in to comment.