Skip to content

Commit

Permalink
Fix merging properties that contain non-array values.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 14, 2012
1 parent 35641cd commit 9b68da3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/Cake/Test/TestCase/Utility/MergeVariablesTraitTest.php
Expand Up @@ -17,8 +17,11 @@
use Cake\Utility\MergeVariablesTrait;

class Base {

use MergeVariablesTrait;

public $hasBoolean = false;

public $listProperty = ['One'];

public $assocProperty = ['Red'];
Expand All @@ -31,6 +34,8 @@ public function mergeVars($properties) {

class Child extends Base {

public $hasBoolean = ['test'];

public $listProperty = ['Two', 'Three'];

public $assocProperty = [
Expand Down Expand Up @@ -86,4 +91,16 @@ public function testMergeVarsAsAssoc() {
];
$this->assertEquals($expected, $object->assocProperty);
}

/**
* Test that merging variables with booleans in the class heirarchy
* doesn't cause issues.
*
* @return void
*/
public function testMergeVarsWithBoolean() {
$object = new Child();
$object->mergeVars(['hasBoolean' => false]);
$this->assertEquals(['test'], $object->hasBoolean);
}
}
4 changes: 3 additions & 1 deletion lib/Cake/Utility/MergeVariablesTrait.php
Expand Up @@ -74,7 +74,9 @@ protected function _mergeProperty($property, $parentClasses, $asAssoc) {
if ($asAssoc) {
$parentProperty = Hash::normalize($parentProperty);
}
$thisValue = Hash::merge($parentProperty, $thisValue);
if (is_array($parentProperty)) {
$thisValue = Hash::merge($parentProperty, $thisValue);
}
}
$this->{$property} = $thisValue;
}
Expand Down

0 comments on commit 9b68da3

Please sign in to comment.