Skip to content

Commit

Permalink
Add test for collapse in collections (#54032)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirmohammadnajmi authored Dec 30, 2024
1 parent f0bf46d commit b5280f0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1735,8 +1735,26 @@ public function testUniqueStrict($collection)
#[DataProvider('collectionClassProvider')]
public function testCollapse($collection)
{
// Normal case: a two-dimensional array with different elements
$data = new $collection([[$object1 = new stdClass], [$object2 = new stdClass]]);
$this->assertEquals([$object1, $object2], $data->collapse()->all());

// Case including numeric and string elements
$data = new $collection([[1], [2], [3], ['foo', 'bar'], new $collection(['baz', 'boom'])]);
$this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], $data->collapse()->all());

// Case with empty two-dimensional arrays
$data = new $collection([[], [], []]);
$this->assertEquals([], $data->collapse()->all());

// Case with both empty arrays and arrays with elements
$data = new $collection([[], [1, 2], [], ['foo', 'bar']]);
$this->assertEquals([1, 2, 'foo', 'bar'], $data->collapse()->all());

// Case including collections and arrays
$collection = new $collection(['baz', 'boom']);
$data = new $collection([[1], [2], [3], ['foo', 'bar'], $collection]);
$this->assertEquals([1, 2, 3, 'foo', 'bar', 'baz', 'boom'], $data->collapse()->all());
}

#[DataProvider('collectionClassProvider')]
Expand Down

0 comments on commit b5280f0

Please sign in to comment.