AmazonSqsReceiver example

$this->connection->reset();
        } catch (HttpException $e) {
            throw new TransportException($e->getMessage(), 0, $e);
        }
    }

    /** * @return MessageCountAwareInterface&ReceiverInterface */
    private function getReceiver(): ReceiverInterface
    {
        return $this->receiver ??= new AmazonSqsReceiver($this->connection, $this->serializer);
    }

    private function getSender(): SenderInterface
    {
        return $this->sender ??= new AmazonSqsSender($this->connection, $this->serializer);
    }
}
class AmazonSqsReceiverTest extends TestCase
{
    public function testItReturnsTheDecodedMessageToTheHandler()
    {
        $serializer = $this->createSerializer();

        $sqsEnvelop = $this->createSqsEnvelope();
        $connection = $this->createMock(Connection::class);
        $connection->method('get')->willReturn($sqsEnvelop);

        $receiver = new AmazonSqsReceiver($connection$serializer);
        $actualEnvelopes = iterator_to_array($receiver->get());
        $this->assertCount(1, $actualEnvelopes);
        $this->assertEquals(new DummyMessage('Hi')$actualEnvelopes[0]->getMessage());
    }

    public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException()
    {
        $this->expectException(MessageDecodingFailedException::class);

        $serializer = $this->createMock(PhpSerializer::class);
        $serializer->method('decode')->willThrowException(new MessageDecodingFailedException());

        
Home | Imprint | This part of the site doesn't use cookies.