From 2361ec3e0d9ed88b0d2293eb4ef515fbf817a9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 2 Apr 2023 09:59:32 +0200 Subject: [PATCH] Fix: Split test --- test/Faker/Provider/BaseTest.php | 44 ++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/test/Faker/Provider/BaseTest.php b/test/Faker/Provider/BaseTest.php index 65ae520c3b..54b2dab9a1 100644 --- a/test/Faker/Provider/BaseTest.php +++ b/test/Faker/Provider/BaseTest.php @@ -548,26 +548,42 @@ public function testRandomElementsThrowsWhenRequestingTooManyKeys(): void BaseProvider::randomElements(['foo'], 2); } - public function testRandomElements(): void + public function testRandomElementsWorksWithoutArgument(): void { self::assertCount(1, BaseProvider::randomElements(), 'Should work without any input'); + } + + public function testRandomElementsWorksWithEmptyArray(): void + { + $randomElements = BaseProvider::randomElements([], 0); + + self::assertIsArray($randomElements); + self::assertCount(0, $randomElements); + } + + public function testRandomElementsWorksWithEmptyTraversable(): void + { + $randomElements = BaseProvider::randomElements(new \ArrayIterator(), 0); + + self::assertIsArray($randomElements); + self::assertCount(0, $randomElements); + } - $empty = BaseProvider::randomElements([], 0); - self::assertIsArray($empty); - self::assertCount(0, $empty); + public function testRandomElementsWorksWithNonEmptyTraversable(): void + { + $randomElements = BaseProvider::randomElements(['foo', 'bar', 'baz'], 3); - $emptyTraversable = BaseProvider::randomElements(new \ArrayIterator(), 0); - self::assertIsArray($emptyTraversable); - self::assertCount(0, $emptyTraversable); + self::assertContains('foo', $randomElements); + self::assertContains('bar', $randomElements); + self::assertContains('baz', $randomElements); + } - $shuffled = BaseProvider::randomElements(['foo', 'bar', 'baz'], 3); - self::assertContains('foo', $shuffled); - self::assertContains('bar', $shuffled); - self::assertContains('baz', $shuffled); + public function testRandomElementsWorksWithAllowDuplicates(): void + { + $randomElements = BaseProvider::randomElements(['foo', 'bar'], 3, true); - $allowDuplicates = BaseProvider::randomElements(['foo', 'bar'], 3, true); - self::assertCount(3, $allowDuplicates); - self::assertContainsOnly('string', $allowDuplicates); + self::assertCount(3, $randomElements); + self::assertContainsOnly('string', $randomElements); } }