|
4 | 4 |
|
5 | 5 | namespace Tests\AymDev\MessengerAzureBundle\Messenger\Transport; |
6 | 6 |
|
| 7 | +use AymDev\MessengerAzureBundle\Messenger\Exception\SerializerDecodingException; |
7 | 8 | use AymDev\MessengerAzureBundle\Messenger\Stamp\AzureMessageStamp; |
8 | 9 | use AymDev\MessengerAzureBundle\Messenger\Transport\AzureTransport; |
9 | 10 | use AymDev\MessengerAzureBundle\Messenger\Stamp\AzureBrokerPropertiesStamp; |
|
12 | 13 | use Symfony\Component\HttpClient\MockHttpClient; |
13 | 14 | use Symfony\Component\HttpClient\Response\MockResponse; |
14 | 15 | use Symfony\Component\Messenger\Envelope; |
| 16 | +use Symfony\Component\Messenger\Exception\MessageDecodingFailedException; |
15 | 17 | use Symfony\Component\Messenger\Exception\TransportException; |
16 | 18 | use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp; |
17 | 19 | use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; |
@@ -86,6 +88,54 @@ public function testGetWithUnexpectedStatusCode(): void |
86 | 88 | $transport->get(); |
87 | 89 | } |
88 | 90 |
|
| 91 | + /** |
| 92 | + * Messages that can't be decoded must throw a converted exception and delete the message |
| 93 | + */ |
| 94 | + public function testGetSerializationExceptionIsConvertedAndDeletesMessage(): void |
| 95 | + { |
| 96 | + self::expectException(SerializerDecodingException::class); |
| 97 | + self::expectExceptionCode(1646061041); |
| 98 | + |
| 99 | + $serializer = self::createMock(SerializerInterface::class); |
| 100 | + $serializer->expects(self::once()) |
| 101 | + ->method('decode') |
| 102 | + ->willThrowException(new MessageDecodingFailedException()); |
| 103 | + |
| 104 | + $location = 'https://test-location/deletion'; |
| 105 | + |
| 106 | + $httpReceiver = new MockHttpClient( |
| 107 | + [ |
| 108 | + new MockResponse('test-body', [ |
| 109 | + 'http_code' => 201, |
| 110 | + 'response_headers' => [ |
| 111 | + 'Location' => $location |
| 112 | + ], |
| 113 | + ]), |
| 114 | + function (string $method, string $url) use ($location): ResponseInterface { |
| 115 | + self::assertSame('DELETE', $method); |
| 116 | + self::assertSame($location, $url); |
| 117 | + |
| 118 | + return new MockResponse(); |
| 119 | + }, |
| 120 | + ] |
| 121 | + ); |
| 122 | + |
| 123 | + $transport = new AzureTransport( |
| 124 | + $serializer, |
| 125 | + new MockHttpClient(), |
| 126 | + $httpReceiver, |
| 127 | + AzureTransport::RECEIVE_MODE_PEEK_LOCK, |
| 128 | + 'test-entity', |
| 129 | + 'test-subscription' |
| 130 | + ); |
| 131 | + |
| 132 | + try { |
| 133 | + $transport->get(); |
| 134 | + } finally { |
| 135 | + self::assertSame(2, $httpReceiver->getRequestsCount()); |
| 136 | + } |
| 137 | + } |
| 138 | + |
89 | 139 | /** |
90 | 140 | * Read messages must be returned in an envelope with specific stamps |
91 | 141 | * @dataProvider provideValidGetCases |
|
0 commit comments