mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Hash::nest() should throw an exception instead of returning an empty array
Refs: https://github.com/cakephp/cakephp/pull/3498#issuecomment-48316204
This commit is contained in:
parent
e410501791
commit
c321a8fa93
2 changed files with 10 additions and 5 deletions
|
@ -2277,8 +2277,9 @@ class HashTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests that nest() returns an empty array for invalid input instead of throwing notices.
|
||||
* Tests that nest() throws an InvalidArgumentException when providing an invalid input.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
* @return void
|
||||
*/
|
||||
public function testNestInvalid() {
|
||||
|
@ -2291,8 +2292,7 @@ class HashTest extends CakeTestCase {
|
|||
)
|
||||
)
|
||||
);
|
||||
$result = Hash::nest($input);
|
||||
$this->assertSame(array(), $result);
|
||||
Hash::nest($input);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1006,6 +1006,7 @@ class Hash {
|
|||
* @param array $options Options are:
|
||||
* @return array of results, nested
|
||||
* @see Hash::extract()
|
||||
* @throws InvalidArgumentException When providing invalid data.
|
||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::nest
|
||||
*/
|
||||
public static function nest(array $data, $options = array()) {
|
||||
|
@ -1048,10 +1049,14 @@ class Hash {
|
|||
}
|
||||
}
|
||||
|
||||
if (!$return) {
|
||||
throw new InvalidArgumentException(__d('cake_dev',
|
||||
'Invalid data array to nest.'
|
||||
));
|
||||
}
|
||||
|
||||
if ($options['root']) {
|
||||
$root = $options['root'];
|
||||
} elseif (!$return) {
|
||||
return array();
|
||||
} else {
|
||||
$root = self::get($return[0], $parentKeys);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue