Skip to content

Commit a52d12c

Browse files
author
Andy Vaughn
committed
all XArray::getAll to return null default value
1 parent 055c42c commit a52d12c

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/XArray.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public function __construct(array $array = null) { $this->array = $array !== nul
8383
* If the found value is a single value, it is wrapped in an array then returned.
8484
*
8585
* @param string $key - the array path to return, i.e. /pages/content
86-
* @param array $default - if the key is not found, this array will be returned
86+
* @param array|null $default - if the key is not found, this array or null will be returned
8787
* @return array|null
8888
*/
89-
public function getAll(string $key = '', array $default = []) : ?array {
89+
public function getAll(string $key = '', ?array $default = []) : ?array {
9090
$array = $this->array;
9191
if($key === '') {
9292
return $array;

tests/XArrayBase/getAll_Test.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ public function Can_get_all_values(array $source, string $xpath, array $expected
3939
// assert
4040
$this->assertEquals($expected, $result);
4141
}
42+
43+
/**
44+
* @test
45+
*/
46+
public function Can_get_null_default_value() {
47+
48+
// arrange
49+
$x = $this->newXArray(['foo' => ['bar', 'baz']]);
50+
51+
// act
52+
$result = $x->getAll('qux', null);
53+
54+
// assert
55+
$this->assertNull($result);
56+
}
4257

4358
/**
4459
* @return array

0 commit comments

Comments
 (0)