|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Mailer\Bridge\Sendgrid\Tests\Http\Api; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Mailer\Bridge\Sendgrid\Http\Api\SendgridTransport; |
| 16 | +use Symfony\Component\Mime\Email; |
| 17 | +use Symfony\Contracts\HttpClient\HttpClientInterface; |
| 18 | +use Symfony\Contracts\HttpClient\ResponseInterface; |
| 19 | + |
| 20 | +class SendgridTransportTest extends TestCase |
| 21 | +{ |
| 22 | + public function testSend() |
| 23 | + { |
| 24 | + $email = new Email(); |
| 25 | + $email->from('foo@example.com') |
| 26 | + ->to('bar@example.com') |
| 27 | + ->bcc('baz@example.com'); |
| 28 | + |
| 29 | + $response = $this->createMock(ResponseInterface::class); |
| 30 | + |
| 31 | + $response |
| 32 | + ->expects($this->once()) |
| 33 | + ->method('getStatusCode') |
| 34 | + ->willReturn(202); |
| 35 | + |
| 36 | + $httpClient = $this->createMock(HttpClientInterface::class); |
| 37 | + |
| 38 | + $httpClient |
| 39 | + ->expects($this->once()) |
| 40 | + ->method('request') |
| 41 | + ->with('POST', 'https://api.sendgrid.com/v3/mail/send', [ |
| 42 | + 'json' => [ |
| 43 | + 'personalizations' => [ |
| 44 | + [ |
| 45 | + 'to' => [['email' => 'bar@example.com']], |
| 46 | + 'subject' => null, |
| 47 | + 'bcc' => [['email' => 'baz@example.com']], |
| 48 | + ], |
| 49 | + ], |
| 50 | + 'from' => ['email' => 'foo@example.com'], |
| 51 | + 'content' => [], |
| 52 | + ], |
| 53 | + 'auth_bearer' => 'foo', |
| 54 | + ]) |
| 55 | + ->willReturn($response); |
| 56 | + |
| 57 | + $mailer = new SendgridTransport('foo', $httpClient); |
| 58 | + |
| 59 | + $mailer->send($email); |
| 60 | + } |
| 61 | +} |
0 commit comments