From 44030846dd4a59d6089790e74255a7bbdeba7778 Mon Sep 17 00:00:00 2001 From: Daniel Winning Date: Wed, 9 Apr 2025 02:48:30 +0100 Subject: [PATCH] Add unit test for count method --- tests/CollectionTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index a03fe0a..ae3379c 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -28,6 +28,13 @@ class CollectionTest extends TestCase $this->assertEquals($expectedResult, $collection->toArray()); } + #[DataProvider('countDataProvider')] + public function testCount(array $items, int $expectedResult): void + { + $collection = new Collection($items); + $this->assertEquals($expectedResult, $collection->count()); + } + public static function addDataProvider(): array { return [ @@ -69,4 +76,22 @@ class CollectionTest extends TestCase ], ]; } + + public static function countDataProvider(): array + { + return [ + [ + 'items' => ['A', 'B', 'C'], + 'expectedResult' => 3, + ], + [ + 'items' => [], + 'expectedResult' => 0, + ], + [ + 'items' => [1, 2, 3, 4, 5], + 'expectedResult' => 5, + ], + ]; + } } \ No newline at end of file