Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Update tests.
  • Loading branch information
farhadhf committed Nov 29, 2024
commit aa92473f647be624666fc8f2fa6bf33f5da0f2fc
Original file line number Diff line number Diff line change
Expand Up @@ -63,76 +63,56 @@ public function testSend()
->html('<html lang="en"><body><p>Test email body</p></body></html>')
->replyTo(new Address('[email protected]', 'Mr. Recipient'));

$response = $this->createMock(JsonMockResponse::class);
$response->method('toArray')->willReturn([
'success_count' => 2,
'fail_count' => 0,
'failed_recipients' => [],
'errors' => [],
]);
$response
->expects($this->once())
->method('getStatusCode')
->willReturn(201);
$httpClient = $this->createMock(MockHttpClient::class);
$httpClient
->expects($this->once())
->method('request')
->with('POST', 'https://send.ahasend.com/v1/email/send', [
'json' => [
'from' => [
'email' => '[email protected]',
'name' => 'Ms. Foo Bar',
],
'recipients' => [
[
'email' => '[email protected]',
'name' => 'Mr. Recipient',
],
[
'email' => '[email protected]',
],
],
'content' => [
'subject' => 'An email',
'text_body' => 'Test email body',
'html_body' => '<html lang="en"><body><p>Test email body</p></body></html>',
'reply_to' => [
'email' => '[email protected]',
'name' => 'Mr. Recipient',
],
'headers' => [
'Bcc' => '[email protected]',
],
],
],
'headers' => [
'X-Api-Key' => 'foo',
],
])
->willReturn($response);

$mailer = new AhaSendApiTransport('foo', $httpClient);
$mailer->send($email);
}

public function testSendDeliveryEventIsDispatched()
{
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
$this->assertSame('POST', $method);
$this->assertSame('https://send.ahasend.com/v1/email/send', $url);
$this->assertStringContainsString('X-Api-Key: foo', $options['headers'][0] ?? $options['request_headers'][0]);

$body = json_decode($options['body'], true);
$this->assertSame('[email protected]', $body['from']['email']);
$this->assertSame('Ms. Foo Bar', $body['from']['name']);
$this->assertSame('[email protected]', $body['recipients'][0]['email']);
$this->assertSame('Mr. Recipient', $body['recipients'][0]['name']);
$this->assertSame('[email protected]', $body['recipients'][1]['email']);
$this->assertArrayNotHasKey('name', $body['recipients'][1]);
$this->assertSame('An email', $body['content']['subject']);
$this->assertSame('Test email body', $body['content']['text_body']);
$this->assertSame('<html lang="en"><body><p>Test email body</p></body></html>', $body['content']['html_body']);
$this->assertSame('[email protected]', $body['content']['reply_to']['email']);
$this->assertSame('Mr. Recipient', $body['content']['reply_to']['name']);
$this->assertSame('[email protected]', $body['content']['headers']['Bcc']);

return new JsonMockResponse([
'success_count' => 0,
'fail_count' => 1,
'failed_recipients' => [
'[email protected]',
],
'errors' => [
'[email protected]: Invalid recipient',
],
'success_count' => 3,
'fail_count' => 0,
'failed_recipients' => [],
'errors' => [],
], [
'http_code' => 201,
]);
});


$mailer = new AhaSendApiTransport('foo', $client);
$mailer->send($email);
}

public function testSendDeliveryEventIsDispatched()
{
$responseFactory = new JsonMockResponse([
'success_count' => 0,
'fail_count' => 1,
'failed_recipients' => [
'[email protected]',
],
'errors' => [
'[email protected]: Invalid recipient',
],
], [
'http_code' => 201,
]);
$client = new MockHttpClient($responseFactory);

$email = new Email();
$email->from(new Address('[email protected]', 'Ms. Foo Bar'))
->to(new Address('[email protected]', 'Mr. Someone'))
Expand Down
Loading