|
| 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\Middleware\AddFifoStamp; |
| 15 | +use Symfony\Component\Messenger\Bridge\AmazonSqs\Middleware\WithMessageDeduplicationId; |
| 16 | +use Symfony\Component\Messenger\Bridge\AmazonSqs\Middleware\WithMessageGroupId; |
| 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 AddFifoStamp(); |
| 26 | + $envelope = new Envelope(new WithMessageGroupIdMessage('groupId')); |
| 27 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 28 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 29 | + $this->assertNotNull($stamp); |
| 30 | + /* @var AmazonSqsFifoStamp $stamp */ |
| 31 | + $this->assertEquals('groupId', $stamp->getMessageGroupId()); |
| 32 | + $this->assertNull($stamp->getMessageDeduplicationId()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testHandleWithDeduplicationIdOnly() |
| 36 | + { |
| 37 | + $middleware = new AddFifoStamp(); |
| 38 | + $envelope = new Envelope(new WithMessageDeduplicationIdMessage('deduplicationId')); |
| 39 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 40 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 41 | + $this->assertNotNull($stamp); |
| 42 | + /* @var AmazonSqsFifoStamp $stamp */ |
| 43 | + $this->assertEquals('deduplicationId', $stamp->getMessageDeduplicationId()); |
| 44 | + $this->assertNull($stamp->getMessageGroupId()); |
| 45 | + } |
| 46 | + |
| 47 | + public function testHandleWithGroupIdAndDeduplicationId() |
| 48 | + { |
| 49 | + $middleware = new AddFifoStamp(); |
| 50 | + $envelope = new Envelope(new WithMessageDeduplicationIdAndMessageGroupIdMessage('my_group', 'my_random_id')); |
| 51 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 52 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 53 | + $this->assertNotNull($stamp); |
| 54 | + /* @var AmazonSqsFifoStamp $stamp */ |
| 55 | + $this->assertEquals('my_random_id', $stamp->getMessageDeduplicationId()); |
| 56 | + $this->assertEquals('my_group', $stamp->getMessageGroupId()); |
| 57 | + } |
| 58 | + |
| 59 | + public function testHandleWithoutId() |
| 60 | + { |
| 61 | + $middleware = new AddFifoStamp(); |
| 62 | + $envelope = new Envelope(new WithoutIdMessage()); |
| 63 | + $finalEnvelope = $middleware->handle($envelope, $this->getStackMock()); |
| 64 | + $stamp = $finalEnvelope->last(AmazonSqsFifoStamp::class); |
| 65 | + /* @var AmazonSqsFifoStamp $stamp */ |
| 66 | + $this->assertNull($stamp); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +class WithMessageDeduplicationIdAndMessageGroupIdMessage implements WithMessageDeduplicationId, WithMessageGroupId |
| 71 | +{ |
| 72 | + private string $messageGroupId; |
| 73 | + private string $messageDeduplicationId; |
| 74 | + |
| 75 | + public function __construct( |
| 76 | + string $messageGroupId, |
| 77 | + string $messageDeduplicationId |
| 78 | + ) { |
| 79 | + $this->messageGroupId = $messageGroupId; |
| 80 | + $this->messageDeduplicationId = $messageDeduplicationId; |
| 81 | + } |
| 82 | + |
| 83 | + public function messageDeduplicationId(): string |
| 84 | + { |
| 85 | + return $this->messageDeduplicationId; |
| 86 | + } |
| 87 | + |
| 88 | + public function messageGroupId(): string |
| 89 | + { |
| 90 | + return $this->messageGroupId; |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +class WithMessageDeduplicationIdMessage implements WithMessageDeduplicationId |
| 95 | +{ |
| 96 | + private string $messageDeduplicationId; |
| 97 | + |
| 98 | + public function __construct( |
| 99 | + string $messageDeduplicationId |
| 100 | + ) { |
| 101 | + $this->messageDeduplicationId = $messageDeduplicationId; |
| 102 | + } |
| 103 | + |
| 104 | + public function messageDeduplicationId(): string |
| 105 | + { |
| 106 | + return $this->messageDeduplicationId; |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +class WithMessageGroupIdMessage implements WithMessageGroupId |
| 111 | +{ |
| 112 | + private string $messageGroupId; |
| 113 | + |
| 114 | + public function __construct( |
| 115 | + string $messageGroupId |
| 116 | + ) { |
| 117 | + $this->messageGroupId = $messageGroupId; |
| 118 | + } |
| 119 | + |
| 120 | + public function messageGroupId(): string |
| 121 | + { |
| 122 | + return $this->messageGroupId; |
| 123 | + } |
| 124 | +} |
| 125 | +class WithoutIdMessage |
| 126 | +{ |
| 127 | +} |
0 commit comments