From 15b4b8e627a3f0897ee71f6bf812a0a8746d8f48 Mon Sep 17 00:00:00 2001 From: Miguel Lima <33354683+vmiguellima@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:29:23 +0000 Subject: [PATCH 1/2] Add ability to get queue name for ansqs event --- src/Event/Sqs/SqsRecord.php | 14 ++++++++++++++ tests/Event/Sqs/SqsRecordTest.php | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/Event/Sqs/SqsRecordTest.php diff --git a/src/Event/Sqs/SqsRecord.php b/src/Event/Sqs/SqsRecord.php index 4c9db8058..13f9e2f03 100644 --- a/src/Event/Sqs/SqsRecord.php +++ b/src/Event/Sqs/SqsRecord.php @@ -57,6 +57,20 @@ public function getReceiptHandle(): string return $this->record['receiptHandle']; } + /** + * Returns the name of the SQS queue that contains the message. + * + * Queue naming constraints: + * + * https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-queues.html + */ + public function getQueueName(): string + { + $parts = explode(':', $this->record['eventSourceARN']); + + return $parts[count($parts) - 1]; + } + /** * Returns the record original data as an array. * diff --git a/tests/Event/Sqs/SqsRecordTest.php b/tests/Event/Sqs/SqsRecordTest.php new file mode 100644 index 000000000..d1277be0d --- /dev/null +++ b/tests/Event/Sqs/SqsRecordTest.php @@ -0,0 +1,17 @@ +assertSame($sqsRecord->getQueueName(), 'my-queue'); + } +} From 36aa4757bc7c42cf3dcbd03e781c8c16719ebd58 Mon Sep 17 00:00:00 2001 From: Miguel Lima <33354683+vmiguellima@users.noreply.github.com> Date: Sat, 11 Nov 2023 23:37:49 +0000 Subject: [PATCH 2/2] Fix php sniffer errors --- src/Event/Sqs/SqsRecord.php | 5 +---- tests/Event/Sqs/SqsRecordTest.php | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Event/Sqs/SqsRecord.php b/src/Event/Sqs/SqsRecord.php index 13f9e2f03..300b27ebc 100644 --- a/src/Event/Sqs/SqsRecord.php +++ b/src/Event/Sqs/SqsRecord.php @@ -59,10 +59,7 @@ public function getReceiptHandle(): string /** * Returns the name of the SQS queue that contains the message. - * - * Queue naming constraints: - * - * https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-queues.html + * Queue naming constraints: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-queues.html */ public function getQueueName(): string { diff --git a/tests/Event/Sqs/SqsRecordTest.php b/tests/Event/Sqs/SqsRecordTest.php index d1277be0d..b83f190ff 100644 --- a/tests/Event/Sqs/SqsRecordTest.php +++ b/tests/Event/Sqs/SqsRecordTest.php @@ -7,9 +7,10 @@ class SqsRecordTest extends TestCase { - public function test_it_can_get_queue_name_from_sqs_event() { + public function test_it_can_get_queue_name_from_sqs_event() + { $event = json_decode(file_get_contents(__DIR__ . '/sqs.json'), true); - + $sqsRecord = new SqsRecord($event['Records'][0]); $this->assertSame($sqsRecord->getQueueName(), 'my-queue');