diff --git a/pkg/sns/SnsProducer.php b/pkg/sns/SnsProducer.php index 7f440c77b..d4eba04d0 100644 --- a/pkg/sns/SnsProducer.php +++ b/pkg/sns/SnsProducer.php @@ -87,6 +87,8 @@ public function send(Destination $destination, Message $message): void } /** + * @throws DeliveryDelayNotSupportedException + * * @return SnsProducer */ public function setDeliveryDelay(int $deliveryDelay = null): Producer @@ -95,7 +97,7 @@ public function setDeliveryDelay(int $deliveryDelay = null): Producer return $this; } - DeliveryDelayNotSupportedException::providerDoestNotSupportIt(); + throw DeliveryDelayNotSupportedException::providerDoestNotSupportIt(); } public function getDeliveryDelay(): ?int @@ -104,6 +106,8 @@ public function getDeliveryDelay(): ?int } /** + * @throws PriorityNotSupportedException + * * @return SnsProducer */ public function setPriority(int $priority = null): Producer @@ -121,6 +125,8 @@ public function getPriority(): ?int } /** + * @throws TimeToLiveNotSupportedException + * * @return SnsProducer */ public function setTimeToLive(int $timeToLive = null): Producer diff --git a/pkg/sns/Tests/SnsProducerTest.php b/pkg/sns/Tests/SnsProducerTest.php index 647988b70..62f8ae4cf 100644 --- a/pkg/sns/Tests/SnsProducerTest.php +++ b/pkg/sns/Tests/SnsProducerTest.php @@ -10,8 +10,11 @@ use Enqueue\Sns\SnsProducer; use Enqueue\Test\ClassExtensionTrait; use Interop\Queue\Destination; +use Interop\Queue\Exception\DeliveryDelayNotSupportedException; use Interop\Queue\Exception\InvalidDestinationException; use Interop\Queue\Exception\InvalidMessageException; +use Interop\Queue\Exception\PriorityNotSupportedException; +use Interop\Queue\Exception\TimeToLiveNotSupportedException; use Interop\Queue\Producer; use PHPUnit\Framework\TestCase; @@ -84,6 +87,48 @@ public function testShouldThrowIfPublishFailed() $producer->send($destination, $message); } + public function testShouldThrowIfsetTimeToLiveIsNotNull() + { + $this->expectException(TimeToLiveNotSupportedException::class); + + $producer = new SnsProducer($this->createSnsContextMock()); + $result = $producer->setTimeToLive(); + + $this->assertInstanceOf(SnsProducer::class, $result); + + $this->expectExceptionMessage('The provider does not support time to live feature'); + + $producer->setTimeToLive(200); + } + + public function testShouldThrowIfsetPriorityIsNotNull() + { + $this->expectException(PriorityNotSupportedException::class); + + $producer = new SnsProducer($this->createSnsContextMock()); + $result = $producer->setPriority(); + + $this->assertInstanceOf(SnsProducer::class, $result); + + $this->expectExceptionMessage('The provider does not support priority feature'); + + $producer->setPriority(200); + } + + public function testShouldThrowIfsetDeliveryDelayIsNotNull() + { + $this->expectException(DeliveryDelayNotSupportedException::class); + + $producer = new SnsProducer($this->createSnsContextMock()); + $result = $producer->setDeliveryDelay(); + + $this->assertInstanceOf(SnsProducer::class, $result); + + $this->expectExceptionMessage('The provider does not support delivery delay feature'); + + $producer->setDeliveryDelay(200); + } + public function testShouldPublish() { $destination = new SnsDestination('queue-name');