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

49 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\SecureRandom;
use PHPUnit\Framework\TestCase;
use Psl\Exception;
use Psl\Math;
use Psl\SecureRandom;
final class IntTest extends TestCase
{
public function testInt(): void
{
$random = SecureRandom\int();
static::assertIsInt($random);
static::assertGreaterThanOrEqual(Math\INT64_MIN, $random);
static::assertLessThanOrEqual(Math\INT64_MAX, $random);
}
public function testIntWithASpecificMin(): void
{
$random = SecureRandom\int(10);
static::assertIsInt($random);
static::assertGreaterThanOrEqual(10, $random);
static::assertLessThanOrEqual(Math\INT64_MAX, $random);
}
public function testIntWithASpecificRange(): void
{
$random = SecureRandom\int(20, 1200);
static::assertIsInt($random);
static::assertGreaterThanOrEqual(20, $random);
static::assertLessThanOrEqual(1200, $random);
}
public function testIntWithMinGreaterThanMax(): void
{
$this->expectException(Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Expected $min (20) to be less than or equal to $max (5).');
SecureRandom\int(20, 5);
}
}