Skip to content

Commit c087576

Browse files
committed
Port changes done to Set into Hash
See #2722
1 parent 6e0e156 commit c087576

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/Cake/Test/Case/Utility/HashTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,28 @@ public function testInsertMulti() {
11131113
$this->assertEquals('value', $result[0]['Comment'][1]['insert']);
11141114
}
11151115

1116+
/**
1117+
* Test that insert() can insert data over a string value.
1118+
*
1119+
* @return void
1120+
*/
1121+
public function testInsertOverwriteStringValue() {
1122+
$data = array(
1123+
'Some' => array(
1124+
'string' => 'value'
1125+
)
1126+
);
1127+
$result = Set::insert($data, 'Some.string.value', array('values'));
1128+
$expected = array(
1129+
'Some' => array(
1130+
'string' => array(
1131+
'value' => array( 'values')
1132+
)
1133+
)
1134+
);
1135+
$this->assertEquals($expected, $result);
1136+
}
1137+
11161138
/**
11171139
* Test remove() method.
11181140
*

lib/Cake/Utility/Hash.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected static function _simpleOp($op, $data, $path, $values = null) {
270270
$_list =& $_list[$key];
271271
}
272272
if (!is_array($_list)) {
273-
return array();
273+
$_list = array();
274274
}
275275
}
276276
if ($op === 'remove') {

0 commit comments

Comments
 (0)