Skip to content

Commit

Permalink
Fix: Split test
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Apr 2, 2023
1 parent feb1640 commit 2361ec3
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions test/Faker/Provider/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 2361ec3

Please sign in to comment.