14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \HttpFoundation \Request ;
16
16
use Symfony \Component \RateLimiter \LimiterInterface ;
17
+ use Symfony \Component \RateLimiter \Policy \NoLimiter ;
17
18
use Symfony \Component \RateLimiter \RateLimit ;
18
19
19
20
class AbstractRequestRateLimiterTest extends TestCase
@@ -33,6 +34,34 @@ public function testConsume(array $rateLimits, ?RateLimit $expected)
33
34
$ this ->assertSame ($ expected , $ rateLimiter ->consume (new Request ()));
34
35
}
35
36
37
+ public function testConsumeWithoutLimiterAddsSpecialNoLimiter ()
38
+ {
39
+ $ rateLimiter = new MockAbstractRequestRateLimiter ([]);
40
+
41
+ try {
42
+ $ this ->assertSame (\PHP_INT_MAX , $ rateLimiter ->consume (new Request ())->getLimit ());
43
+ } catch (\TypeError $ error ) {
44
+ if (str_contains ($ error ->getMessage (), 'RateLimit::__construct(): Argument #1 ($availableTokens) must be of type int, float given ' )) {
45
+ $ this ->markTestSkipped ('This test cannot be run on a version of the RateLimiter component that uses \INF instead of \PHP_INT_MAX in NoLimiter. ' );
46
+ }
47
+
48
+ throw $ error ;
49
+ }
50
+ }
51
+
52
+ public function testResetLimiters ()
53
+ {
54
+ $ rateLimiter = new MockAbstractRequestRateLimiter ([
55
+ $ limiter1 = $ this ->createMock (LimiterInterface::class),
56
+ $ limiter2 = $ this ->createMock (LimiterInterface::class),
57
+ ]);
58
+
59
+ $ limiter1 ->expects ($ this ->once ())->method ('reset ' );
60
+ $ limiter2 ->expects ($ this ->once ())->method ('reset ' );
61
+
62
+ $ rateLimiter ->reset (new Request ());
63
+ }
64
+
36
65
public static function provideRateLimits ()
37
66
{
38
67
$ now = new \DateTimeImmutable ();
0 commit comments