|
2 | 2 |
|
3 | 3 | namespace Illuminate\Tests\Mail; |
4 | 4 |
|
| 5 | +use Aws\Ses\SesClient; |
5 | 6 | use Illuminate\Config\Repository; |
6 | 7 | use Illuminate\Container\Container; |
7 | 8 | use Illuminate\Mail\MailManager; |
| 9 | +use Illuminate\Mail\Transport\SesTransport; |
| 10 | +use Illuminate\View\Factory; |
| 11 | +use Mockery as m; |
8 | 12 | use PHPUnit\Framework\TestCase; |
| 13 | +use Symfony\Component\Mime\Email; |
9 | 14 |
|
10 | 15 | class MailSesTransportTest extends TestCase |
11 | 16 | { |
| 17 | + protected function tearDown(): void |
| 18 | + { |
| 19 | + m::close(); |
| 20 | + |
| 21 | + parent::tearDown(); |
| 22 | + } |
| 23 | + |
12 | 24 | public function testGetTransport() |
13 | 25 | { |
14 | 26 | $container = new Container; |
15 | 27 |
|
16 | 28 | $container->singleton('config', function () { |
17 | 29 | return new Repository([ |
18 | 30 | 'services.ses' => [ |
| 31 | + 'key' => 'foo', |
| 32 | + 'secret' => 'bar', |
19 | 33 | 'region' => 'us-east-1', |
20 | 34 | ], |
21 | 35 | ]); |
22 | 36 | }); |
23 | 37 |
|
24 | 38 | $manager = new MailManager($container); |
25 | 39 |
|
| 40 | + /** @var \Illuminate\Mail\Transport\SesTransport $transport */ |
26 | 41 | $transport = $manager->createSymfonyTransport(['transport' => 'ses']); |
27 | 42 |
|
28 | | - $this->assertSame('ses+api://random_key@us-east-1', $transport->__toString()); |
| 43 | + $ses = $transport->ses(); |
| 44 | + |
| 45 | + $this->assertSame('us-east-1', $ses->getRegion()); |
| 46 | + |
| 47 | + $this->assertSame('ses', (string) $transport); |
| 48 | + } |
| 49 | + |
| 50 | + public function testSend() |
| 51 | + { |
| 52 | + $message = new Email(); |
| 53 | + $message->subject('Foo subject'); |
| 54 | + $message->text('Bar body'); |
| 55 | + $message-> sender( '[email protected]'); |
| 56 | + $message-> to( '[email protected]'); |
| 57 | + $message-> bcc( '[email protected]'); |
| 58 | + |
| 59 | + $client = m::mock(SesClient::class); |
| 60 | + $client->shouldReceive('sendRawEmail')->once(); |
| 61 | + |
| 62 | + (new SesTransport($client))->send($message); |
| 63 | + } |
| 64 | + |
| 65 | + public function testSesLocalConfiguration() |
| 66 | + { |
| 67 | + $container = new Container; |
| 68 | + |
| 69 | + $container->singleton('config', function () { |
| 70 | + return new Repository([ |
| 71 | + 'mail' => [ |
| 72 | + 'mailers' => [ |
| 73 | + 'ses' => [ |
| 74 | + 'transport' => 'ses', |
| 75 | + 'region' => 'eu-west-1', |
| 76 | + 'options' => [ |
| 77 | + 'ConfigurationSetName' => 'Laravel', |
| 78 | + 'Tags' => [ |
| 79 | + ['Name' => 'Laravel', 'Value' => 'Framework'], |
| 80 | + ], |
| 81 | + ], |
| 82 | + ], |
| 83 | + ], |
| 84 | + ], |
| 85 | + 'services' => [ |
| 86 | + 'ses' => [ |
| 87 | + 'region' => 'us-east-1', |
| 88 | + ], |
| 89 | + ], |
| 90 | + ]); |
| 91 | + }); |
| 92 | + |
| 93 | + $container->instance('view', $this->createMock(Factory::class)); |
| 94 | + |
| 95 | + $container->bind('events', function () { |
| 96 | + return null; |
| 97 | + }); |
| 98 | + |
| 99 | + $manager = new MailManager($container); |
| 100 | + |
| 101 | + /** @var \Illuminate\Mail\Mailer $mailer */ |
| 102 | + $mailer = $manager->mailer('ses'); |
| 103 | + |
| 104 | + /** @var \Illuminate\Mail\Transport\SesTransport $transport */ |
| 105 | + $transport = $mailer->getSymfonyTransport(); |
| 106 | + |
| 107 | + $this->assertSame('eu-west-1', $transport->ses()->getRegion()); |
| 108 | + |
| 109 | + $this->assertSame([ |
| 110 | + 'ConfigurationSetName' => 'Laravel', |
| 111 | + 'Tags' => [ |
| 112 | + ['Name' => 'Laravel', 'Value' => 'Framework'], |
| 113 | + ], |
| 114 | + ], $transport->getOptions()); |
29 | 115 | } |
30 | 116 | } |
0 commit comments