-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to define category of mail
- Loading branch information
1 parent
2edc6e9
commit 7de5a9c
Showing
2 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,69 @@ public function testCanGetTransport() | |
); | ||
} | ||
|
||
public function testCanSendPlainEmailWithCategory() | ||
{ | ||
// Mock client | ||
$client = \Mockery::mock(\GuzzleHttp\ClientInterface::class); | ||
$driver = $this->app['swift.transport']->driver('mailtrap'); | ||
$driver->setClient($client); | ||
|
||
$args = []; | ||
$client | ||
->shouldReceive('request') | ||
->once() | ||
->andReturnUsing(function (...$params) use (&$args) { | ||
$args = $params; | ||
|
||
$body = \Mockery::mock(\Psr\Http\Message\StreamInterface::class); | ||
$body->shouldReceive('getContents')->andReturn(json_encode([ | ||
'success' => true, | ||
'message_ids' => [ | ||
123 | ||
], | ||
])); | ||
|
||
$response = \Mockery::mock(\Psr\Http\Message\ResponseInterface::class); | ||
$response->shouldReceive('getBody')->andReturn($body); | ||
|
||
return $response; | ||
}); | ||
|
||
/** @var \Illuminate\Mail\Mailer */ | ||
$mailer = $this->app['mailer']; | ||
|
||
// Send test email | ||
$mailer->raw('Hello World', function ($mail) { | ||
->to('[email protected]') | ||
->subject('Test email'); | ||
|
||
$mail->getHeaders()->addTextHeader( | ||
'X-Mailtrap-Category', | ||
'test' | ||
); | ||
}); | ||
|
||
// Check arguments passed to Guzzle | ||
$this->assertEquals('POST', $args[0]); | ||
$this->assertEquals('https://send.api.mailtrap.io/api/send', $args[1]); | ||
|
||
// Check payload | ||
$payload = $args[2]; | ||
$this->assertEquals('foo', $payload['headers']['Api-Token']); | ||
$this->assertEquals([ | ||
'email' => '[email protected]', | ||
'name' => 'Manage It', | ||
], $payload['json']['from']); | ||
$this->assertEquals([ | ||
'email' => '[email protected]', | ||
], $payload['json']['to'][0]); | ||
$this->assertEquals('Test email', $payload['json']['subject']); | ||
$this->assertEquals('test', $payload['json']['category']); | ||
$this->assertEquals('Hello World', $payload['json']['text']); | ||
$this->assertArrayNotHasKey('html', $payload['json']); | ||
} | ||
|
||
public function testCanSendHtmlEmail() | ||
{ | ||
// Mock client | ||
|
@@ -34,7 +97,19 @@ public function testCanSendHtmlEmail() | |
->once() | ||
->andReturnUsing(function (...$params) use (&$args) { | ||
$args = $params; | ||
return \Mockery::mock(\Psr\Http\Message\ResponseInterface::class); | ||
|
||
$body = \Mockery::mock(\Psr\Http\Message\StreamInterface::class); | ||
$body->shouldReceive('getContents')->andReturn(json_encode([ | ||
'success' => true, | ||
'message_ids' => [ | ||
123 | ||
], | ||
])); | ||
|
||
$response = \Mockery::mock(\Psr\Http\Message\ResponseInterface::class); | ||
$response->shouldReceive('getBody')->andReturn($body); | ||
|
||
return $response; | ||
}); | ||
|
||
/** @var \Illuminate\Mail\Mailer */ | ||
|
@@ -63,6 +138,7 @@ public function testCanSendHtmlEmail() | |
], $payload['json']['to'][0]); | ||
$this->assertEquals('Test email', $payload['json']['subject']); | ||
$this->assertEquals('<h1>Hello World</h1>', $payload['json']['html']); | ||
$this->assertArrayNotHasKey('text', $payload['json']); | ||
} | ||
|
||
public function testCanSendMailable() | ||
|
@@ -78,7 +154,19 @@ public function testCanSendMailable() | |
->once() | ||
->andReturnUsing(function (...$params) use (&$args) { | ||
$args = $params; | ||
return \Mockery::mock(\Psr\Http\Message\ResponseInterface::class); | ||
|
||
$body = \Mockery::mock(\Psr\Http\Message\StreamInterface::class); | ||
$body->shouldReceive('getContents')->andReturn(json_encode([ | ||
'success' => true, | ||
'message_ids' => [ | ||
123 | ||
], | ||
])); | ||
|
||
$response = \Mockery::mock(\Psr\Http\Message\ResponseInterface::class); | ||
$response->shouldReceive('getBody')->andReturn($body); | ||
|
||
return $response; | ||
}); | ||
|
||
/** @var \Illuminate\Mail\Mailer */ | ||
|