8000 Merge branch '5.3' into 5.4 · symfony/symfony@acbd7b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit acbd7b4

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: [FrameworkBundle] Trigger deprecations on stderr instead of using trigger_deprecation call Fix wait duration for fixed window policy
2 parents 4d96f84 + a972a6a commit acbd7b4

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
156156
$xliffVersion = $input->getOption('xliff-version') ?? '1.2';
157157

158158
if ($input->getOption('xliff-version')) {
159-
trigger_deprecation('symfony/framework-bundle', '5.3', 'The "--xliff-version" option is deprecated, use "--format=xlf%d" instead.', 10 * $xliffVersion);
159+
$errorIo->warning(sprintf('The "--xliff-version" option is deprecated since version 5.3, use "--format=xlf%d" instead.', 10 * $xliffVersion));
160160
}
161161

162162
if ($input->getOption('output-format')) {
163-
trigger_deprecation('symfony/framework-bundle', '5.3', 'The "--output-format" option is deprecated, use "--format=xlf%d" instead.', 10 * $xliffVersion);
163+
$errorIo->warning(sprintf('The "--output-format" option is deprecated since version 5.3, use "--format=xlf%d" instead.', 10 * $xliffVersion));
164164
}
165165

166166
if (\in_array($format, array_keys(self::FORMATS), true)) {

src/Symfony/Component/Messenger/Command/AbstractFailedMessagesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected function printPendingMessagesMessage(ReceiverInterface $receiver, Symf
183183
protected function getReceiver(/* string $name = null */): ReceiverInterface
184184
{
185185
if (1 > \func_num_args() && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
186-
trigger_error_deprecation('symfony/messenger', '5.3', 'The "%s()" method will have a new "string $name" argument in version 6.0, not defining it is deprecated.', __METHOD__);
186+
trigger_deprecation('symfony/messenger', '5.3', 'The "%s()" method will have a new "string $name" argument in version 6.0, not defining it is deprecated.', __METHOD__);
187187
}
188188
$name = \func_num_args() > 0 ? func_get_arg(0) : null;
189189

src/Symfony/Component/RateLimiter/Policy/FixedWindowLimiter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation
6868

6969
$reservation = new Reservation($now, new RateLimit($window->getAvailableTokens($now), \DateTimeImmutable::createFromFormat('U', floor($now)), true, $this->limit));
7070
} else {
71-
$remainingTokens = $tokens - $availableTokens;
72-
$waitDuration = $window->calculateTimeForTokens($remainingTokens);
71+
$waitDuration = $window->calculateTimeForTokens($tokens);
7372

7473
if (null !== $maxTime && $waitDuration > $maxTime) {
7574
// process needs to wait longer than set interval

src/Symfony/Component/RateLimiter/Tests/Policy/FixedWindowLimiterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ClockMock;
1616
use Symfony\Component\RateLimiter\Policy\FixedWindowLimiter;
17+
use Symfony\Component\RateLimiter\RateLimit;
1718
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
1819
use Symfony\Component\RateLimiter\Tests\Resources\DummyWindow;
1920
use Symfony\Component\RateLimiter\Util\TimeUtil;
@@ -30,6 +31,7 @@ protected function setUp(): void
3031
$this->storage = new InMemoryStorage();
3132

3233
ClockMock::register(InMemoryStorage::class);
34+
ClockMock::register(RateLimit::class);
3335
}
3436

3537
public function testConsume()
@@ -69,6 +71,20 @@ public function testConsumeOutsideInterval(string $dateIntervalString)
6971
$this->assertTrue($rateLimit->isAccepted());
7072
}
7173

74+
public function testWaitIntervalOnConsumeOverLimit()
75+
{
76+
$limiter = $this->createLimiter();
77+
78+
// initial consume
79+
$limiter->consume(8);
80+
// consumer over the limit
81+
$rateLimit = $limiter->consume(4);
82+
83+
$start = microtime(true);
84+
$rateLimit->wait(); // wait 1 minute
85+
$this->assertEqualsWithDelta($start + 60, microtime(true), 0.5);
86+
}
87+
7288
public function testWrongWindowFromCache()
7389
{
7490
$this->storage->save(new DummyWindow());

src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowLimiterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\PhpUnit\ClockMock;
1616
use Symfony\Component\RateLimiter\Exception\ReserveNotSupportedException;
1717
use Symfony\Component\RateLimiter\Policy\SlidingWindowLimiter;
18+
use Symfony\Component\RateLimiter\RateLimit;
1819
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
1920

2021
/**
@@ -29,6 +30,7 @@ protected function setUp(): void
2930
$this->storage = new InMemoryStorage();
3031

3132
ClockMock::register(InMemoryStorage::class);
33+
ClockMock::register(RateLimit::class);
3234
}
3335

3436
public function testConsume()
@@ -53,6 +55,20 @@ public function testConsume()
5355
$this->assertSame(10, $rateLimit->getLimit());
5456
}
5557

58+
public function testWaitIntervalOnConsumeOverLimit()
59+
{
60+
$limiter = $this->createLimiter();
61+
62+
// initial consume
63+
$limiter->consume(8);
64+
// consumer over the limit
65+
$rateLimit = $limiter->consume(4);
66+
67+
$start = microtime(true);
68+
$rateLimit->wait(); // wait 12 seconds
69+
$this->assertEqualsWithDelta($start + 12, microtime(true), 0.5);
70+
}
71+
5672
public function testReserve()
5773
{
5874
$this->expectException(ReserveNotSupportedException::class);

src/Symfony/Component/RateLimiter/Tests/Policy/TokenBucketLimiterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\RateLimiter\Policy\Rate;
1818
use Symfony\Component\RateLimiter\Policy\TokenBucket;
1919
use Symfony\Component\RateLimiter\Policy\TokenBucketLimiter;
20+
use Symfony\Component\RateLimiter\RateLimit;
2021
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
2122
use Symfony\Component\RateLimiter\Tests\Resources\DummyWindow;
2223

@@ -34,6 +35,7 @@ protected function setUp(): void
3435
ClockMock::register(TokenBucketLimiter::class);
3536
ClockMock::register(InMemoryStorage::class);
3637
ClockMock::register(TokenBucket::class);
38+
ClockMock::register(RateLimit::class);
3739
}
3840

3941
public function testReserve()
@@ -89,6 +91,20 @@ public function testConsume()
8991
$this->assertSame(10, $rateLimit->getLimit());
9092
}
9193

94+
public function testWaitIntervalOnConsumeOverLimit()
95+
{
96+
$limiter = $this->createLimiter();
97+
98+
// initial consume
99+
$limiter->consume(8);
100+
// consumer over the limit
101+
$rateLimit = $limiter->consume(4);
102+
103+
$start = microtime(true);
104+
$rateLimit->wait(); // wait 1 second
105+
$this->assertEqualsWithDelta($start + 1, microtime(true), 0.5);
106+
}
107+
92108
public function testWrongWindowFromCache()
93109
{
94110
$this->storage->save(new DummyWindow());

0 commit comments

Comments
 (0)
0