Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.x] Add test for collapse in collections #54032

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading