Skip to content

Commit b5280f0

Browse files
Add test for collapse in collections (#54032)
1 parent f0bf46d commit b5280f0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/Support/SupportCollectionTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,26 @@ public function testUniqueStrict($collection)
17351735
#[DataProvider('collectionClassProvider')]
17361736
public function testCollapse($collection)
17371737
{
1738+
// Normal case: a two-dimensional array with different elements
17381739
$data = new $collection([[$object1 = new stdClass], [$object2 = new stdClass]]);
17391740
$this->assertEquals([$object1, $object2], $data->collapse()->all());
1741+
1742+
// Case including numeric and string elements
1743+
$data = new $collection([[1], [2], [3], ['foo', 'bar'], new $collection(['baz', 'boom'])]);
1744+
$this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], $data->collapse()->all());
1745+
1746+
// Case with empty two-dimensional arrays
1747+
$data = new $collection([[], [], []]);
1748+
$this->assertEquals([], $data->collapse()->all());
1749+
1750+
// Case with both empty arrays and arrays with elements
1751+
$data = new $collection([[], [1, 2], [], ['foo', 'bar']]);
1752+
$this->assertEquals([1, 2, 'foo', 'bar'], $data->collapse()->all());
1753+
1754+
// Case including collections and arrays
1755+
$collection = new $collection(['baz', 'boom']);
1756+
$data = new $collection([[1], [2], [3], ['foo', 'bar'], $collection]);
1757+
$this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], $data->collapse()->all());
17401758
}
17411759

17421760
#[DataProvider('collectionClassProvider')]

0 commit comments

Comments
 (0)