Skip to content

Commit a99803f

Browse files
extssebastianbergmann
authored andcommitted
Added support for ArrayAccess based arrays in
1 parent 8a0cfb0 commit a99803f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Framework/Assert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public static function assertArrayHasKey($key, $array, $message = '')
6262
*/
6363
public static function assertArraySubset($subset, $array, $strict = false, $message = '')
6464
{
65-
if (!is_array($subset)) {
65+
if (!(is_array($subset) || $subset instanceof ArrayAccess)) {
6666
throw PHPUnit_Util_InvalidArgumentHelper::factory(
6767
1,
6868
'array or ArrayAccess'
6969
);
7070
}
7171

72-
if (!is_array($array)) {
72+
if (!(is_array($array) || $array instanceof ArrayAccess)) {
7373
throw PHPUnit_Util_InvalidArgumentHelper::factory(
7474
2,
7575
'array or ArrayAccess'

tests/Framework/AssertTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public function testAssertArraySubset()
182182
$this->assertArraySubset(array('a' => 'item a', 'c' => array('a2' => 'item a2')), $array);
183183
$this->assertArraySubset(array('a' => 'item a', 'd' => array('a2' => array('b3' => 'item b3'))), $array);
184184

185+
$arrayAccessData = new ArrayObject($array);
186+
187+
$this->assertArraySubset(['a' => 'item a', 'c' => ['a2' => 'item a2']], $arrayAccessData);
188+
$this->assertArraySubset(['a' => 'item a', 'd' => ['a2' => ['b3' => 'item b3']]], $arrayAccessData);
189+
185190
try {
186191
$this->assertArraySubset(array('a' => 'bad value'), $array);
187192
} catch (PHPUnit_Framework_AssertionFailedError $e) {

0 commit comments

Comments
 (0)