8000 [Messenger] Fixed BC layer for RedeliveryStamp · symfony/symfony@ac3c4d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac3c4d7

Browse files
Nyholmnicolas-grekas
authored andcommitted
[Messenger] Fixed BC layer for RedeliveryStamp
1 parent 79cd966 commit ac3c4d7

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

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

Lines 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

Lines 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