8000 [Mailer] Send email tag to Postmark API by AndreiIgna · Pull Request #34766 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Send email tag to Postmark API #34766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated - test for PostmarkApi transport
  • Loading branch information
AndreiIgna committed Dec 19, 2019
commit db116cf12083119eb0bc7e41a8af22233b26a723
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkApiTransport;
use Symfony\Component\Mime\Email;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

class PostmarkApiTransportTest extends TestCase
{
Expand Down Expand Up @@ -41,4 +44,56 @@ public function getTransportData()
],
];
}

public function testSend()
{
$email = new Email();
$email->from('foo@example.com')
->to('bar@example.com')
->bcc('baz@example.com')
->subject('testing email')
->text('content');
$email->getHeaders()->addTextHeader('Tag', 'example-tag');

$response = $this->createMock(ResponseInterface::class);

$response
->expects($this->once())
->method('getStatusCode')
->willReturn(200);
$response
->expects($this->once())
->method('toArray')
->willReturn(["ErrorCode" => 0, "Message" => "OK", "MessageID" => "123", "To" => "bar@example.com"]);

$httpClient = $this->createMock(HttpClientInterface::class);

$httpClient
->expects($this->once())
->method('request')
->with('POST', 'https://api.postmarkapp.com/email', [
'json' => [
'From' => 'foo@ex 6D31 ample.com',
'To' => 'bar@example.com',
'Cc' => '',
'Bcc' => 'baz@example.com',
'ReplyTo' => '',
'Subject' => 'testing email',
'TextBody' => 'content',
'HtmlBody' => null,
'Attachments' => [],
'Tag' => 'example-tag',
],
'headers' => [
'Accept' => 'application/json',
'X-Postmark-Server-Token' => 'foo',
],
])
->willReturn($response);

$mailer = new PostmarkApiTransport('foo', $httpClient);
$sentMessage = $mailer->send($email);

$this->assertSame('123', $sentMessage->getMessageId());
}
}
0