2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Random;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-12-25 19:11:35 +01:00
|
|
|
use Psl\Exception;
|
|
|
|
use Psl\Random;
|
|
|
|
use Psl\Str;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class BytesTest extends TestCase
|
|
|
|
{
|
2019-12-25 19:11:35 +01:00
|
|
|
public function testBytes(): void
|
|
|
|
{
|
|
|
|
$random = Random\bytes(32);
|
|
|
|
|
|
|
|
self::assertSame(32, Str\Byte\length($random));
|
|
|
|
}
|
|
|
|
|
2019-12-26 15:41:15 +01:00
|
|
|
public function testBytesEarlyReturnForZeroLength(): void
|
|
|
|
{
|
|
|
|
self::assertSame('', Random\bytes(0));
|
|
|
|
}
|
|
|
|
|
2019-12-25 19:11:35 +01:00
|
|
|
public function testBytesThrowsForNegativeLength(): void
|
|
|
|
{
|
|
|
|
$this->expectException(Exception\InvariantViolationException::class);
|
2020-07-09 00:28:29 +02:00
|
|
|
$this->expectExceptionMessage('Expected a non-negative length.');
|
2019-12-25 19:11:35 +01:00
|
|
|
|
|
|
|
Random\bytes(-1);
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|