1+ <?php
2+
3+
4+ namespace MiamiOH \SnsHandler \Testing ;
5+
6+ use Illuminate \Testing \TestResponse ;
7+ use MiamiOH \SnsHandler \SnsTopicMapper ;
8+
9+ /**
10+ * Trait ReceivesSnsMessages
11+ * @package MiamiOH\SnsHandler\Testing
12+ *
13+ * @codeCoverageIgnore
14+ * Just a test helper
15+ */
16+ trait ReceivesSnsMessages
17+ {
18+ public function mapSnsTopicToHandler (array $ snsTopicMap ): void
19+ {
20+ //ARN => Class
21+ $ this ->app ->bind (SnsTopicMapper::class, function () use ($ snsTopicMap ) {
22+ return new SnsTopicMapper ($ snsTopicMap );
23+ });
24+ }
25+
26+ public function sendSnsMessage (string $ arn , string $ data ): TestResponse
27+ {
28+ $ headers = [
29+ 'x-amz-sns-message-type ' => 'Notification ' ,
30+ 'x-amz-sns-message-id ' => '22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324 ' ,
31+ 'x-amz-sns-topic-arn ' => $ arn ,
32+ 'x-amz-sns-subscription-arn ' => 'arn:aws:sns:us-west-2:123456789012:EntityRequest:c9135db0-26c4-47ec-8998-413945fb5a96 ' ,
33+ 'Content-Length ' => '773 ' ,
34+ 'Content-Type ' => 'text/plain; charset=UTF-8 ' ,
35+ 'Host ' => 'example.com ' ,
36+ 'Connection ' => 'Keep-Alive ' ,
37+ 'User-Agent ' => 'Amazon Simple Notification Service Agent ' ,
38+ ];
39+ $ body = [
40+ 'Type ' => 'Notification ' ,
41+ 'MessageId ' => '22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324 ' ,
42+ 'TopicArn ' => $ arn ,
43+ 'Subject ' => 'My First Message ' ,
44+ 'Message ' => $ data ,
45+ 'Timestamp ' => '2012-05-02T00:54:06.655Z ' ,
46+ 'SignatureVersion ' => '1 ' ,
47+ 'Signature ' => 'EXAMPLEw6JRN... ' ,
48+ 'SigningCertURL ' => 'https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem ' ,
49+ 'UnsubscribeURL ' => 'https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a9 ' ,
50+ ];
51+
52+ $ response = $ this ->postJson ('/api/sns/message ' , $ body , $ headers );
53+
54+ }
55+
56+ }
0 commit comments