AmazonSesHandlerTest.php in Amazon SES 2.0.x
File
tests/src/Kernel/AmazonSesHandlerTest.php
View source
<?php
namespace Drupal\Tests\amazon_ses\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;
use Prophecy\Argument;
class AmazonSesHandlerTest extends KernelTestBase {
protected $prophecy;
protected static $modules = [
'amazon_ses',
];
protected function setUp() : void {
parent::setUp();
$this->prophecy = $this
->prophesize(SesClient::class);
}
public function testSend($message) {
$message_id = $this
->randomString();
$this->prophecy
->sendEmail(Argument::type('array'))
->willReturn([
'MessageId' => $message_id,
]);
$client = $this->prophecy
->reveal();
$this->container
->set('amazon_ses.client', $client);
$handler = $this->container
->get('amazon_ses.handler');
$return = $handler
->send($message);
$this
->assertEquals($return, $message_id);
}
public function testFailedSend($message) {
$this->prophecy
->sendEmail(Argument::type('array'))
->willThrow(SesException::class);
$client = $this->prophecy
->reveal();
$this->container
->set('amazon_ses.client', $client);
$handler = $this->container
->get('amazon_ses.handler');
$return = $handler
->send($message);
$this
->assertFalse($return);
}
public function messageData() {
return [
[
[
'to' => 'success@simulator.amazonses.com',
'from' => 'test@example.com',
'subject' => 'Amazon SES test',
'body' => 'test message body',
'headers' => [
'Content-Type' => 'text/plain',
],
],
],
];
}
}