Skip to content

Commit bfae515

Browse files
committed
bug #34474 [Messenger] Ignore stamps in in-memory transport (tienvx)
This PR was merged into the 4.4 branch. Discussion ---------- [Messenger] Ignore stamps in in-memory transport | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | N/A <!-- required for new features --> Stamps can be added/removed to/from message during handling. Ignore stamps so that we can ack/reject them correctly. <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- b435b1a [Messenger] Ignore stamps in in-memory transport
2 parents a7fe2b2 + b435b1a commit bfae515

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Symfony/Component/Messenger/Tests/Transport/InMemoryTransportTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Messenger\Envelope;
16+
use Symfony\Component\Messenger\Tests\Fixtures\AnEnvelopeStamp;
1617
use Symfony\Component\Messenger\Transport\InMemoryTransport;
1718

1819
/**
@@ -50,6 +51,19 @@ public function testQueue()
5051
$this->assertSame([], $this->transport->get());
5152
}
5253

54+
public function testAcknowledgeSameMessageWithDifferentStamps()
55+
{
56+
$envelope1 = new Envelope(new \stdClass(), [new AnEnvelopeStamp()]);
57+
$this->transport->send($envelope1);
58+
$envelope2 = new Envelope(new \stdClass(), [new AnEnvelopeStamp()]);
59+
$this->transport->send($envelope2);
60+
$this->assertSame([$envelope1, $envelope2], $this->transport->get());
61+
$this->transport->ack($envelope1->with(new AnEnvelopeStamp()));
62+
$this->assertSame([$envelope2], $this->transport->get());
63+
$this->transport->reject($envelope2->with(new AnEnvelopeStamp()));
64+
$this->assertSame([], $this->transport->get());
65+
}
66+
5367
public function testAck()
5468
{
5569
$envelope = new Envelope(new \stdClass());

src/Symfony/Component/Messenger/Transport/InMemoryTransport.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function get(): iterable
5555
public function ack(Envelope $envelope): void
5656
{
5757
$this->acknowledged[] = $envelope;
58-
$id = spl_object_hash($envelope);
58+
$id = spl_object_hash($envelope->getMessage());
5959
unset($this->queue[$id]);
6060
}
6161

@@ -65,7 +65,7 @@ public function ack(Envelope $envelope): void
6565
public function reject(Envelope $envelope): void
6666
{
6767
$this->rejected[] = $envelope;
68-
$id = spl_object_hash($envelope);
68+
$id = spl_object_hash($envelope->getMessage());
6969
unset($this->queue[$id]);
7070
}
7171

@@ -75,7 +75,7 @@ public function reject(Envelope $envelope): void
7575
public function send(Envelope $envelope): Envelope
7676
{
7777
$this->sent[] = $envelope;
78-
$id = spl_object_hash($envelope);
78+
$id = spl_object_hash($envelope->getMessage());
7979
$this->queue[$id] = $envelope;
8080

8181
return $envelope;

0 commit comments

Comments
 (0)