|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Messenger\Bridge\AmazonSqs\Tests\Middleware; |
| 13 | + |
| 14 | +use Symfony\Component\Messenger\Bridge\AmazonSqs\MessageDeduplicationAwareInterface; |
| 15 | +use Symfony\Component\Messenger\Bridge\AmazonSqs\MessageGroupAwareInterface; |
| 16 | +use Symfony\Component\Messenger\Bridge\AmazonSqs\Middleware\AddFifoStampMiddleware; |
| 17 | +use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsFifoStamp; |
| 18 | +use Symfony\Component\Messenger\Envelope; |
| 19 | +use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase; |
| 20 | + |
| 21 | +class AddFifoStampTest extends MiddlewareTestCase |
| 22 | +{ |
| 23 | + public function testAddStampWithGroupIdOnly() |
| 24 | + { |
| 25 | + $middleware = new AddFifoStampMiddleware(); |
| 26 | + $envelope = new Envelope(new WithMessageGroupIdMessage('groupId')); |
| 27 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 28 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 29 | + $this->assertInstanceOf(AmazonSqsFifoStamp::class, $stamp); |
| 30 | + $this->assertSame('groupId', $stamp->getMessageGroupId()); |
| 31 | + $this->assertNull($stamp->getMessageDeduplicationId()); |
| 32 | + } |
| 33 | + |
| 34 | + public function testHandleWithDeduplicationIdOnly() |
| 35 | + { |
| 36 | + $middleware = new AddFifoStampMiddleware(); |
| 37 | + $envelope = new Envelope(new WithMessageDeduplicationIdMessage('deduplicationId')); |
| 38 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 39 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 40 | + $this->assertInstanceOf(AmazonSqsFifoStamp::class, $stamp); |
| 41 | + $this->assertSame('deduplicationId', $stamp->getMessageDeduplicationId()); |
| 42 | + $this->assertNull($stamp->getMessageGroupId()); |
| 43 | + } |
| 44 | + |
| 45 | + public function testHandleWithGroupIdAndDeduplicationId() |
| 46 | + { |
| 47 | + $middleware = new AddFifoStampMiddleware(); |
| 48 | + $envelope = new Envelope(new WithMessageDeduplicationIdAndMessageGroupIdMessage('my_group', 'my_random_id')); |
| 49 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 50 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 51 | + $this->assertInstanceOf(AmazonSqsFifoStamp::class, $stamp); |
| 52 | + $this->assertSame('my_random_id', $stamp->getMessageDeduplicationId()); |
| 53 | + $this->assertSame('my_group', $stamp->getMessageGroupId()); |
| 54 | + } |
| 55 | + |
| 56 | + public function testHandleWithoutId() |
| 57 | + { |
| 58 | + $middleware = new AddFifoStampMiddleware(); |
| 59 | + $envelope = new Envelope(new WithoutIdMessage()); |
| 60 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 61 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 62 | + $this->assertNull($stamp); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +class WithMessageDeduplicationIdAndMessageGroupIdMessage implements MessageDeduplicationAwareInterface, MessageGroupAwareInterface |
| 67 | +{ |
| 68 | + public function __construct( |
| 69 | + private string $messageGroupId, |
| 70 | + private string $messageDeduplicationId, |
| 71 | + ) { |
| 72 | + } |
| 73 | + |
| 74 | + public function getMessageDeduplicationId(): ?string |
| 75 | + { |
| 76 | + return $this->messageDeduplicationId; |
| 77 | + } |
| 78 | + |
| 79 | + public function getMessageGroupId(): ?string |
| 80 | + { |
| 81 | + return $this->messageGroupId; |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +class WithMessageDeduplicationIdMessage implements MessageDeduplicationAwareInterface |
| 86 | +{ |
| 87 | + public function __construct( |
| 88 | + private string $messageDeduplicationId, |
| 89 | + ) { |
| 90 | + } |
| 91 | + |
| 92 | + public function getMessageDeduplicationId(): ?string |
| 93 | + { |
| 94 | + return $this->messageDeduplicationId; |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +class WithMessageGroupIdMessage implements MessageGroupAwareInterface |
| 99 | +{ |
| 100 | + public function __construct( |
| 101 | + private string $messageGroupId, |
| 102 | + ) { |
| 103 | + } |
| 104 | + |
| 105 | + public function getMessageGroupId(): ?string |
| 106 | + { |
| 107 | + return $this->messageGroupId; |
| 108 | + } |
| 109 | +} |
| 110 | +class WithoutIdMessage |
| 111 | +{ |
| 112 | +} |
0 commit comments