|
12 | 12 | namespace Symfony\Component\RateLimiter\Tests;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Bridge\PhpUnit\ClockMock; |
15 | 16 | use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
|
16 | 17 | use Symfony\Component\RateLimiter\Policy\FixedWindowLimiter;
|
17 | 18 | use Symfony\Component\RateLimiter\Policy\NoLimiter;
|
@@ -76,4 +77,37 @@ public static function invalidConfigProvider()
|
76 | 77 | 'policy' => 'token_bucket',
|
77 | 78 | ]];
|
78 | 79 | }
|
| 80 | + |
| 81 | + /** |
| 82 | + * @group time-sensitive |
| 83 | + */ |
| 84 | + public function testExpirationTimeCalculationWhenUsingDefaultTimezoneRomeWithIntervalAfterCETChange() |
| 85 | + { |
| 86 | + $originalTimezone = date_default_timezone_get(); |
| 87 | + try { |
| 88 | + // Timestamp for 'Sun 27 Oct 2024 12:59:40 AM UTC' that's just 20 seconds before switch CEST->CET |
| 89 | + ClockMock::withClockMock(1729990780); |
| 90 | + |
| 91 | + // This is a prerequisite for the bug to happen |
| 92 | + date_default_timezone_set('Europe/Rome'); |
| 93 | + |
| 94 | + $storage = new InMemoryStorage(); |
| 95 | + $factory = new RateLimiterFactory( |
| 96 | + [ |
| 97 | + 'id' => 'id_1', |
| 98 | + 'policy' => 'fixed_window', |
| 99 | + 'limit' => 30, |
| 100 | + 'interval' => '21 seconds', |
| 101 | + ], |
| 102 | + $storage |
| 103 | + ); |
| 104 | + $rateLimiter = $factory->create('key'); |
| 105 | + $rateLimiter->consume(1); |
| 106 | + $limiterState = $storage->fetch('id_1-key'); |
| 107 | + // As expected the expiration is equal to the interval we defined |
| 108 | + $this->assertSame(21, $limiterState->getExpirationTime()); |
| 109 | + } finally { |
| 110 | + date_default_timezone_set($originalTimezone); |
| 111 | + } |
| 112 | + } |
79 | 113 | }
|
0 commit comments