Skip to content

Commit ed9f3dc

Browse files
committed
Fix matching when arrays are identical
1 parent cb0e412 commit ed9f3dc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Diff for: src/Spies/MatchArray.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ public function is_match( $actual ) {
1111
return false;
1212
}
1313
$match_count = 0;
14+
$is_associative = $this->is_associative( $actual );
1415
foreach ( $this->expected_array as $key => $value ) {
15-
// Compare associative arrays
16-
if ( array_key_exists( $key, $actual ) && $actual[ $key ] === $value ) {
17-
$match_count += 1;
18-
}
19-
// Compare indexed arrays
20-
if ( ! $this->is_associative( $actual ) && in_array( $value, $actual ) ) {
21-
$match_count += 1;
16+
if ( $is_associative ) {
17+
// Compare associative arrays
18+
if ( array_key_exists( $key, $actual ) && $actual[ $key ] === $value ) {
19+
$match_count += 1;
20+
}
21+
} else {
22+
// Compare indexed arrays
23+
if ( ! $this->is_associative( $actual ) && in_array( $value, $actual ) ) {
24+
$match_count += 1;
25+
}
2226
}
2327
}
2428
return ( count( $this->expected_array ) === $match_count );

0 commit comments

Comments
 (0)