Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1864689

Browse filesBrowse files
bug symfony#42059 [Messenger] Fixed BC layer for RedeliveryStamp (Nyholm)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [Messenger] Fixed BC layer for RedeliveryStamp | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Related to symfony#41319 (comment) | License | MIT | Doc PR | n/a In Symfony 6, the second argument to RedeliveryStamp's constructor will be a DateTimeInterface. We should already allow people to instantiate this object with the Symfony 6 way. Commits ------- ac3c4d7 [Messenger] Fixed BC layer for RedeliveryStamp
2 parents 79cd966 + ac3c4d7 commit 1864689
Copy full SHA for 1864689

File tree

Expand file treeCollapse file tree

2 files changed

+48
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+48
-4
lines changed

‎src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,27 @@ final class RedeliveryStamp implements StampInterface
2424
private $exceptionMessage;
2525
private $flattenException;
2626

27-
public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
27+
/**
28+
* @param \DateTimeInterface|null $exceptionMessage
29+
*/
30+
public function __construct(int $retryCount, $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
2831
{
2932
$this->retryCount = $retryCount;
3033
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
34+
if (null !== $redeliveredAt) {
35+
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$redeliveredAt" as 4th argument of the "%s::__construct()" is deprecated, pass "$redeliveredAt" as second argument instead.', self::class));
36+
}
3137

32-
if (null !== $exceptionMessage) {
38+
if ($exceptionMessage instanceof \DateTimeInterface) {
39+
// In Symfony 6.0, the second argument will be $redeliveredAt
40+
$this->redeliveredAt = $exceptionMessage;
41+
if (null !== $redeliveredAt) {
42+
throw new \LogicException('It is deprecated to specify a redeliveredAt as 4th argument. The correct way is to specify redeliveredAt as the second argument. Using both is not allowed.');
43+
}
44+
} elseif (null !== $exceptionMessage) {
3345
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$exceptionMessage" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
46+
$this->exceptionMessage = $exceptionMessage;
3447
}
35-
$this->exceptionMessage = $exceptionMessage;
3648

3749
if (null !== $flattenException) {
3850
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$flattenException" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));

‎src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Stamp/RedeliveryStampTest.php
+33-1Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Messenger\Tests\Stamp;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;
1617

1718
class RedeliveryStampTest extends TestCase
1819
{
20+
use ExpectDeprecationTrait;
21+
1922
public function testGetters()
2023
{
2124
$stamp = new RedeliveryStamp(10);
@@ -25,7 +28,36 @@ public function testGetters()
2528

2629
public function testSerialization()
2730
{
28-
$stamp = new RedeliveryStamp(10, null, null, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000'));
31+
$stamp = new RedeliveryStamp(10, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000'));
2932
$this->assertSame('2005-08-15T15:52:01+0000', $stamp->getRedeliveredAt()->format(\DateTimeInterface::ISO8601));
3033
}
34+
35+
public function testRedeliveryAt()
36+
{
37+
$redeliveredAt = new \DateTimeImmutable('+2minutes');
38+
$stamp = new RedeliveryStamp(10, $redeliveredAt);
39+
$this->assertSame($redeliveredAt, $stamp->getRedeliveredAt());
40+
}
41+
42+
/**
43+
* @group legacy
44+
*/
45+
public function testLegacyRedeliveryAt()
46+
{
47+
$this->expectDeprecation('Since symfony/messenger 5.2: Using the "$redeliveredAt" as 4th argument of the "Symfony\Component\Messenger\Stamp\RedeliveryStamp::__construct()" is deprecated, pass "$redeliveredAt" as second argument instead.');
48+
$redeliveredAt = new \DateTimeImmutable('+2minutes');
49+
$stamp = new RedeliveryStamp(10, null, null, $redeliveredAt);
50+
$this->assertSame($redeliveredAt, $stamp->getRedeliveredAt());
51+
}
52+
53+
/**
54+
* @group legacy
55+
*/
56+
public function testPassingBothLegacyAndCurrentRedeliveryAt()
57+
{
58+
$this->expectDeprecation('Since symfony/messenger 5.2: Using the "$redeliveredAt" as 4th argument of the "Symfony\Component\Messenger\Stamp\RedeliveryStamp::__construct()" is deprecated, pass "$redeliveredAt" as second argument instead.');
59+
$redeliveredAt = new \DateTimeImmutable('+2minutes');
60+
$this->expectException(\LogicException::class);
61+
new RedeliveryStamp(10, $redeliveredAt, null, $redeliveredAt);
62+
}
3163
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.