Skip to content
Permalink
Browse files

Add argument type check.

  • Loading branch information...
ADmad committed Sep 30, 2015
1 parent 7d73cdc commit b10a082971902205ee9e06e1f3d8c51b14bb05ae
Showing with 18 additions and 0 deletions.
  1. +6 −0 src/Utility/Hash.php
  2. +12 −0 tests/TestCase/Utility/HashTest.php
@@ -122,6 +122,12 @@ public static function get($data, $path, $default = null)
*/
public static function extract($data, $path)
{
if (!(is_array($data) || $data instanceof ArrayAccess)) {
throw new InvalidArgumentException(
'Invalid data type, must be an array or \ArrayAccess instance.'
);
}
if (empty($path)) {
return $data;
}
@@ -879,6 +879,18 @@ public function testNumeric()
$this->assertTrue(Hash::numeric($data));
}
/**
* Test passing invalid argument type
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid data type, must be an array or \ArrayAccess instance.
* @return void
*/
public function testExtractInvalidArgument()
{
Hash::extract('foo', '');
}
/**
* Test simple paths.
*

0 comments on commit b10a082

Please sign in to comment.
You can’t perform that action at this time.