mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-02 17:56:09 +01:00
34 lines
738 B
PHP
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);
|
|
}
|
|
}
|