Skip to content

Commit 5645879

Browse files
Add test for Arr::reject method (#54863)
This commit adds test coverage for the Arr::reject method which filters an array using the negation of a given callback. The test verifies: - Basic rejection behavior with sequential arrays - Key preservation with associative arrays
1 parent 7b8e12d commit 5645879

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: tests/Support/SupportArrTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -1533,4 +1533,32 @@ public function testSelect()
15331533
[],
15341534
], Arr::select($array, null));
15351535
}
1536+
1537+
public function testReject()
1538+
{
1539+
$array = [1, 2, 3, 4, 5, 6];
1540+
1541+
// Test rejection behavior (removing even numbers)
1542+
$result = Arr::reject($array, function ($value) {
1543+
return $value % 2 === 0;
1544+
});
1545+
1546+
$this->assertEquals([
1547+
0 => 1,
1548+
2 => 3,
1549+
4 => 5,
1550+
], $result);
1551+
1552+
// Test key preservation with associative array
1553+
$assocArray = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
1554+
1555+
$result = Arr::reject($assocArray, function ($value) {
1556+
return $value > 2;
1557+
});
1558+
1559+
$this->assertEquals([
1560+
'a' => 1,
1561+
'b' => 2,
1562+
], $result);
1563+
}
15361564
}

0 commit comments

Comments
 (0)