endtoend-test-psl/tests/Psl/Arr/RandomTest.php

30 lines
628 B
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Arr;
use PHPUnit\Framework\TestCase;
2019-12-25 00:35:14 +01:00
use Psl\Arr;
use Psl\Exception;
2019-12-24 01:52:07 +01:00
class RandomTest extends TestCase
{
2019-12-25 00:35:14 +01:00
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([]);
}
2019-12-24 01:52:07 +01:00
}