endtoend-test-psl/tests/Psl/Arr/RandomTest.php
2019-12-25 19:46:58 +01:00

30 lines
628 B
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Arr;
use PHPUnit\Framework\TestCase;
use Psl\Arr;
use Psl\Exception;
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 testRandomThrowsWhenTheGivenArrayIsEmpty(): void
{
$this->expectException(Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Expected non-empty-array.');
Arr\random([]);
}
}