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 2e29489
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/Faker/Provider/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,66 @@ public function testRandomElements(): void
self::assertCount(3, $allowDuplicates);
self::assertContainsOnly('string', $allowDuplicates);
}

public function testRandomElements(): void
{
self::assertCount(1, BaseProvider::randomElements(), 'Should work without any input');

$empty = BaseProvider::randomElements([], 0);
self::assertIsArray($empty);
self::assertCount(0, $empty);

$emptyTraversable = BaseProvider::randomElements(new \ArrayIterator(), 0);
self::assertIsArray($emptyTraversable);
self::assertCount(0, $emptyTraversable);

$shuffled = BaseProvider::randomElements(['foo', 'bar', 'baz'], 3);
self::assertContains('foo', $shuffled);
self::assertContains('bar', $shuffled);
self::assertContains('baz', $shuffled);

$allowDuplicates = BaseProvider::randomElements(['foo', 'bar'], 3, true);
self::assertCount(3, $allowDuplicates);
self::assertContainsOnly('string', $allowDuplicates);
}

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);
}

public function testRandomElementsWorksWithNonEmptyTraversable(): void
{
$randomElements = BaseProvider::randomElements(['foo', 'bar', 'baz'], 3);

self::assertContains('foo', $randomElements);
self::assertContains('bar', $randomElements);
self::assertContains('baz', $randomElements);
}

public function testRandomElementsWorksWithAllowDuplicates(): void
{
$randomElements = BaseProvider::randomElements(['foo', 'bar'], 3, true);

self::assertCount(3, $randomElements);
self::assertContainsOnly('string', $randomElements);
}
}

/**
Expand Down

0 comments on commit 2e29489

Please sign in to comment.