[RateLimiter] Fix infinite values with NoLimiter

This commit is contained in:
YaFou 2021-01-20 20:59:41 +01:00
parent 3811030f26
commit 4f9eedfcf7
No known key found for this signature in database
GPG Key ID: A112DE339CED408A
2 changed files with 34 additions and 2 deletions

View File

@ -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

View File

@ -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());
}
}