From 6048c04a5812ccf4c9dded1876c75688fedf3375 Mon Sep 17 00:00:00 2001 From: Amir Najmi Date: Sat, 28 Dec 2024 15:26:25 +0330 Subject: [PATCH] Add test for collapse in collections --- tests/Support/SupportCollectionTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index beaa1f84109d..134c35b7539b 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -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')]