Skip to content

Commit

Permalink
Adding a line to the docs of Hash and a test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Feb 18, 2016
1 parent 9040b7f commit 138927a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Utility/Hash.php
Expand Up @@ -113,6 +113,7 @@ public static function get($data, $path, $default = null)
* - `{n}.User[id]` Get the name of every user with an id key.
* - `{n}.User[id>=2]` Get the name of every user with an id key greater than or equal to 2.
* - `{n}.User[username=/^paul/]` Get User elements with username matching `^paul`.
* - `{n}.User[id=1].name` Get the Users name with id matching `1`.
*
* @param array|\ArrayAccess $data The data to extract from.
* @param string $path The path to extract.
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase/Utility/HashTest.php
Expand Up @@ -892,6 +892,21 @@ public function testExtractInvalidArgument()
Hash::extract('foo', '');
}

/**
* Test the extraction of a single value filtered by another field.
*
* @dataProvider articleDataSets
* @return void
*/
public function testExtractSingleValueWithFilteringByAnotherField($data)
{
$result = Hash::extract($data, '{*}.Article[id=1].title');
$this->assertEquals([0 => 'First Article'], $result);

$result = Hash::extract($data, '{*}.Article[id=2].title');
$this->assertEquals([0 => 'Second Article'], $result);
}

/**
* Test simple paths.
*
Expand Down

0 comments on commit 138927a

Please sign in to comment.