Skip to content

Commit 1da365e

Browse files
committed
Merge branch 'add-helper-trait' into 'initial-setup'
Create a new trait to assist with testing the sns handler See merge request it/soldel-packages/sns-handler!4
2 parents 2321033 + 4e626dc commit 1da365e

File tree

2 files changed

+73
-26
lines changed

2 files changed

+73
-26
lines changed

phpunit.xml

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="Unit">
13-
<directory suffix="Test.php">./tests/Unit</directory>
14-
</testsuite>
15-
16-
<testsuite name="Feature">
17-
<directory suffix="Test.php">./tests/Feature</directory>
18-
</testsuite>
19-
</testsuites>
20-
<filter>
21-
<whitelist processUncoveredFilesFromWhitelist="true">
22-
<directory suffix=".php">./src</directory>
23-
</whitelist>
24-
</filter>
25-
<php>
26-
<env name="APP_ENV" value="testing"/>
27-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Unit">
10+
<directory suffix="Test.php">./tests/Unit</directory>
11+
</testsuite>
12+
<testsuite name="Feature">
13+
<directory suffix="Test.php">./tests/Feature</directory>
14+
</testsuite>
15+
</testsuites>
16+
<php>
17+
<env name="APP_ENV" value="testing"/>
18+
</php>
2819
</phpunit>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)