8000 [Messenger] Fixed BC layer for RedeliveryStamp by Nyholm · Pull Request #42059 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Fixed BC layer for RedeliveryStamp #42059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,27 @@ final class RedeliveryStamp implements StampInterface
private $exceptionMessage;
private $flattenException;

public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
/**
* @param \DateTimeInterface|null $exceptionMessage
*/
public function __construct(int $retryCount, $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
{
$this->retryCount = $retryCount;
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();
if (null !== $redeliveredAt) {
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));
}

if (null !== $exceptionMessage) {
if ($exceptionMessage instanceof \DateTimeInterface) {
// In Symfony 6.0, the second argument will be $redeliveredAt
$this->redeliveredAt = $exceptionMessage;
if (null !== $redeliveredAt) {
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.');
}
} elseif (null !== $exceptionMessage) {
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));
$this->exceptionMessage = $exceptionMessage;
}
$this->exceptionMessage = $exceptionMessage;

if (null !== $flattenException) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
namespace Symfony\Component\Messenger\Tests\Stamp;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;

class RedeliveryStampTest extends TestCase
{
use ExpectDeprecationTrait;

public function testGetters()
{
$stamp = new RedeliveryStamp(10);
Expand All @@ -25,7 +28,36 @@ public function testGetters()

public function testSerialization()
{
$stamp = new RedeliveryStamp(10, null, null, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000'));
$stamp = new RedeliveryStamp(10, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000'));
$this->assertSame('2005-08-15T15:52:01+0000', $stamp->getRedeliveredAt()->format(\DateTimeInterface::ISO8601));
}

public function testRedeliveryAt()
{
$redeliveredAt = new \DateTimeImmutable('+2minutes');
$stamp = new RedeliveryStamp(10, $redeliveredAt);
$this->assertSame($redeliveredAt, $stamp->getRedeliveredAt());
}

/**
* @group legacy
*/
public function testLegacyRedeliveryAt()
{
$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.');
$redeliveredAt = new \DateTimeImmutable('+2minutes');
$stamp = new RedeliveryStamp(10, null, null, $redeliveredAt);
$this->assertSame($redeliveredAt, $stamp->getRedeliveredAt());
}

/**
* @group legacy
*/
public function testPassingBothLegacyAndCurrentRedeliveryAt()
{
$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.');
$redeliveredAt = new \DateTimeImmutable('+2minutes');
$this->expectException(\LogicException::class);
new RedeliveryStamp(10, $redeliveredAt, null, $redeliveredAt);
}
}
0