[RateLimiter] Fix infinite values with NoLimiter
This commit is contained in:
parent
3811030f26
commit
4f9eedfcf7
@ -29,12 +29,12 @@ final class NoLimiter implements LimiterInterface
|
||||
{
|
||||
public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
|
||||
{
|
||||
return new Reservation(time(), new RateLimit(\INF, new \DateTimeImmutable(), true, \INF));
|
||||
return new Reservation(time(), new RateLimit(\PHP_INT_MAX, new \DateTimeImmutable(), true, \PHP_INT_MAX));
|
||||
}
|
||||
|
||||
public function consume(int $tokens = 1): RateLimit
|
||||
{
|
||||
return new RateLimit(\INF, new \DateTimeImmutable(), true, \INF);
|
||||
return new RateLimit(\PHP_INT_MAX, new \DateTimeImmutable(), true, \PHP_INT_MAX);
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\RateLimiter\Tests\Policy;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\RateLimiter\Policy\NoLimiter;
|
||||
use Symfony\Component\RateLimiter\RateLimit;
|
||||
use Symfony\Component\RateLimiter\Reservation;
|
||||
|
||||
class NoLimiterTest extends TestCase
|
||||
{
|
||||
public function testConsume()
|
||||
{
|
||||
$limiter = new NoLimiter();
|
||||
$this->assertInstanceOf(RateLimit::class, $limiter->consume());
|
||||
}
|
||||
|
||||
public function testReserve()
|
||||
{
|
||||
$limiter = new NoLimiter();
|
||||
$this->assertInstanceOf(Reservation::class, $limiter->reserve());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user