Skip to content

Commit

Permalink
Merge pull request #13 from stefanzweifel/move-trait
Browse files Browse the repository at this point in the history
Move `GeneratesSnsMessages` trait to public
  • Loading branch information
rennokki authored Jul 8, 2021
2 parents 8f5e749 + 6070de2 commit 33c115d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,45 @@ class MyEventbridgeController extends EventbridgeWebhook
}
```

## Testing SES Controllers

The package comes with a `GeneratesSnsMessages`-trait to create a valid SES payload to be used for your tests.
Use the trait like in the example below to get started writing tests for your own controllers.

```php
use RenokiCo\AwsWebhooks\Concerns\GeneratesSnsMessages;

class MySesControllerTest extends TestCase
{
use GeneratesSnsMessages;

public static function setUpBeforeClass(): void
{
static::initializeSsl();
}

public static function tearDownAfterClass(): void
{
static::tearDownSsl();
}

public function getSesMessage(string $type): array
{
return $this->getNotificationPayload([
'eventType' => $type,
]);
}

public function test_my_ses_controller()
{
$payload = $this->getSesMessage('Bounce');

$response = $this->withHeaders($this->getHeadersForMessage($payload))
->json('GET', route('ses', ['certificate' => static::$certificate]), $payload);
}
}
```

## 🐛 Testing

``` bash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace RenokiCo\AwsWebhooks\Test\Concerns;
namespace RenokiCo\AwsWebhooks\Concerns;

use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace RenokiCo\AwsWebhooks\Test;

use Orchestra\Testbench\TestCase as Orchestra;
use RenokiCo\AwsWebhooks\Concerns\GeneratesSnsMessages;

abstract class TestCase extends Orchestra
{
use Concerns\GeneratesSnsMessages;
use GeneratesSnsMessages;

/**
* {@inheritdoc}
Expand Down

0 comments on commit 33c115d

Please sign in to comment.