mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-12 09:09:45 +01:00
38 lines
806 B
PHP
38 lines
806 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psl\Arr;
|
|
use Psl\Exception;
|
|
|
|
final class RandomTest extends TestCase
|
|
{
|
|
public function testRandom(): void
|
|
{
|
|
$values = ['a', 'b', 'c'];
|
|
$value = Arr\random($values);
|
|
|
|
static::assertNotNull($value);
|
|
static::assertContains($value, $values);
|
|
}
|
|
|
|
public function testRandomWithOneItem(): void
|
|
{
|
|
$values = ['a'];
|
|
$value = Arr\random($values);
|
|
|
|
static::assertSame('a', $value);
|
|
}
|
|
|
|
public function testRandomThrowsWhenTheGivenArrayIsEmpty(): void
|
|
{
|
|
$this->expectException(Exception\InvariantViolationException::class);
|
|
$this->expectExceptionMessage('Expected a non-empty-array.');
|
|
|
|
Arr\random([]);
|
|
}
|
|
}
|