endtoend-test-psl/tests/Psl/SecureRandom/IntTest.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
2020-07-16 18:13:12 +02:00
namespace Psl\Tests\SecureRandom;
2019-12-24 01:52:07 +01:00
use PHPUnit\Framework\TestCase;
2019-12-25 19:11:35 +01:00
use Psl\Exception;
use Psl\Math;
2020-07-16 18:13:12 +02:00
use Psl\SecureRandom;
2019-12-24 01:52:07 +01:00
final class IntTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2019-12-25 19:11:35 +01:00
public function testInt(): void
{
2020-07-16 18:13:12 +02:00
$random = SecureRandom\int();
2019-12-25 19:11:35 +01:00
static::assertIsInt($random);
static::assertGreaterThanOrEqual(Math\INT64_MIN, $random);
static::assertLessThanOrEqual(Math\INT64_MAX, $random);
2019-12-25 19:11:35 +01:00
}
public function testIntWithASpecificMin(): void
{
2020-07-16 18:13:12 +02:00
$random = SecureRandom\int(10);
2019-12-25 19:11:35 +01:00
static::assertIsInt($random);
static::assertGreaterThanOrEqual(10, $random);
static::assertLessThanOrEqual(Math\INT64_MAX, $random);
2019-12-25 19:11:35 +01:00
}
public function testIntWithASpecificRange(): void
{
2020-07-16 18:13:12 +02:00
$random = SecureRandom\int(20, 1200);
2019-12-25 19:11:35 +01:00
static::assertIsInt($random);
static::assertGreaterThanOrEqual(20, $random);
static::assertLessThanOrEqual(1200, $random);
2019-12-25 19:11:35 +01:00
}
public function testIntWithMinGreaterThanMax(): void
{
$this->expectException(Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Expected $min (20) to be less than or equal to $max (5).');
2020-07-16 18:13:12 +02:00
SecureRandom\int(20, 5);
2019-12-25 19:11:35 +01:00
}
2019-12-24 01:52:07 +01:00
}