Skip to content

Commit 33c115d

Browse files
authored
Merge pull request #13 from stefanzweifel/move-trait
Move `GeneratesSnsMessages` trait to public
2 parents 8f5e749 + 6070de2 commit 33c115d

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,45 @@ class MyEventbridgeController extends EventbridgeWebhook
253253
}
254254
```
255255

256+
## Testing SES Controllers
257+
258+
The package comes with a `GeneratesSnsMessages`-trait to create a valid SES payload to be used for your tests.
259+
Use the trait like in the example below to get started writing tests for your own controllers.
260+
261+
```php
262+
use RenokiCo\AwsWebhooks\Concerns\GeneratesSnsMessages;
263+
264+
class MySesControllerTest extends TestCase
265+
{
266+
use GeneratesSnsMessages;
267+
268+
public static function setUpBeforeClass(): void
269+
{
270+
static::initializeSsl();
271+
}
272+
273+
public static function tearDownAfterClass(): void
274+
{
275+
static::tearDownSsl();
276+
}
277+
278+
public function getSesMessage(string $type): array
279+
{
280+
return $this->getNotificationPayload([
281+
'eventType' => $type,
282+
]);
283+
}
284+
285+
public function test_my_ses_controller()
286+
{
287+
$payload = $this->getSesMessage('Bounce');
288+
289+
$response = $this->withHeaders($this->getHeadersForMessage($payload))
290+
->json('GET', route('ses', ['certificate' => static::$certificate]), $payload);
291+
}
292+
}
293+
```
294+
256295
## 🐛 Testing
257296

258297
``` bash

tests/Concerns/GeneratesSnsMessages.php src/Concerns/GeneratesSnsMessages.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace RenokiCo\AwsWebhooks\Test\Concerns;
3+
namespace RenokiCo\AwsWebhooks\Concerns;
44

55
use Aws\Sns\Message;
66
use Aws\Sns\MessageValidator;

tests/TestCase.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace RenokiCo\AwsWebhooks\Test;
44

55
use Orchestra\Testbench\TestCase as Orchestra;
6+
use RenokiCo\AwsWebhooks\Concerns\GeneratesSnsMessages;
67

78
abstract class TestCase extends Orchestra
89
{
9-
use Concerns\GeneratesSnsMessages;
10+
use GeneratesSnsMessages;
1011

1112
/**
1213
* {@inheritdoc}

0 commit comments

Comments
 (0)