endtoend-test-psl/tests/Psl/SecureRandom/BytesTest.php
2020-10-15 11:05:30 +02:00

34 lines
738 B
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\SecureRandom;
use PHPUnit\Framework\TestCase;
use Psl\Exception;
use Psl\SecureRandom;
use Psl\Str;
final class BytesTest extends TestCase
{
public function testBytes(): void
{
$random = SecureRandom\bytes(32);
static::assertSame(32, Str\Byte\length($random));
}
public function testBytesEarlyReturnForZeroLength(): void
{
static::assertSame('', SecureRandom\bytes(0));
}
public function testBytesThrowsForNegativeLength(): void
{
$this->expectException(Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Expected a non-negative length.');
SecureRandom\bytes(-1);
}
}