-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a717509
commit 9cfbc39
Showing
2 changed files
with
20 additions
and
85 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 |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
use Illuminated\Console\Tests\App\Console\Commands\EmailNotificationsInvalidRecipientsCommand; | ||
use Illuminated\Console\Tests\TestCase; | ||
use Monolog\Handler\DeduplicationHandler; | ||
use Monolog\Handler\NativeMailerHandler; | ||
use Monolog\Handler\SwiftMailerHandler; | ||
use Monolog\Logger; | ||
use Swift_Message; | ||
|
@@ -23,17 +22,6 @@ public function it_validates_and_filters_notification_recipients() | |
$this->assertNotInstanceOf(SwiftMailerHandler::class, $command->emailChannelHandler()); | ||
} | ||
|
||
/** @test */ | ||
public function it_is_disabled_on_null_driver() | ||
{ | ||
config(['mail.driver' => 'null']); | ||
|
||
/** @var EmailNotificationsCommand $command */ | ||
$command = $this->runArtisan(new EmailNotificationsCommand); | ||
|
||
$this->assertFalse($command->createEmailChannelHandler()); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver() | ||
{ | ||
|
@@ -71,21 +59,10 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driv | |
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler()); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_configured_monolog_native_mailer_handler_on_other_drivers() | ||
{ | ||
config(['mail.driver' => 'any-other']); | ||
|
||
/** @var EmailNotificationsCommand $command */ | ||
$command = $this->runArtisan(new EmailNotificationsCommand); | ||
|
||
$this->assertMailerHandlersEqual($this->composeNativeMailerHandler(), $command->emailChannelHandler()); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_configured_monolog_deduplication_handler_if_deduplication_enabled() | ||
{ | ||
config(['mail.driver' => 'any-other']); | ||
config(['mail.driver' => 'sendmail']); | ||
|
||
/** @var EmailNotificationsDeduplicationCommand $command */ | ||
$command = $this->runArtisan(new EmailNotificationsDeduplicationCommand); | ||
|
@@ -98,43 +75,18 @@ public function it_uses_configured_monolog_deduplication_handler_if_deduplicatio | |
/** | ||
* Compose "swift mailer" handler. | ||
* | ||
* @param string $name | ||
* @return \Monolog\Handler\SwiftMailerHandler | ||
*/ | ||
private function composeSwiftMailerHandler() | ||
private function composeSwiftMailerHandler($name = 'email-notifications-command') | ||
{ | ||
$handler = new SwiftMailerHandler(app('mailer')->getSwiftMailer(), $this->composeMailerHandlerMessage(), Logger::NOTICE); | ||
$handler = new SwiftMailerHandler(app('mailer')->getSwiftMailer(), $this->composeMailerHandlerMessage($name), Logger::NOTICE); | ||
|
||
$handler->setFormatter(new MonologHtmlFormatter); | ||
|
||
return $handler; | ||
} | ||
|
||
/** | ||
* Compose "native mailer" handler. | ||
* | ||
* @param string $name | ||
* @return \Monolog\Handler\NativeMailerHandler | ||
*/ | ||
private function composeNativeMailerHandler(string $name = 'email-notifications-command') | ||
{ | ||
$handler = new NativeMailerHandler( | ||
to_rfc2822_email([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => '[email protected]', 'name' => 'Jane Smith'], | ||
]), | ||
"[TESTING] %level_name% in `{$name}` command", | ||
to_rfc2822_email([ | ||
'address' => '[email protected]', | ||
'name' => 'ICLogger Notification', | ||
]), | ||
Logger::NOTICE | ||
); | ||
$handler->setContentType('text/html'); | ||
$handler->setFormatter(new MonologHtmlFormatter); | ||
|
||
return $handler; | ||
} | ||
|
||
/** | ||
* Compose "deduplication" handler. | ||
* | ||
|
@@ -143,20 +95,21 @@ private function composeNativeMailerHandler(string $name = 'email-notifications- | |
private function composeDeduplicationHandler() | ||
{ | ||
return new DeduplicationHandler( | ||
$this->composeNativeMailerHandler('email-notifications-deduplication-command'), null, Logger::NOTICE, 60 | ||
$this->composeSwiftMailerHandler('email-notifications-deduplication-command'), null, Logger::NOTICE, 60 | ||
); | ||
} | ||
|
||
/** | ||
* Compose mailer handler message. | ||
* | ||
* @param string $name | ||
* @return \Swift_Message | ||
*/ | ||
private function composeMailerHandlerMessage() | ||
private function composeMailerHandlerMessage($name = 'email-notifications-command') | ||
{ | ||
/** @var Swift_Message $message */ | ||
$message = app('mailer')->getSwiftMailer()->createMessage(); | ||
$message->setSubject('[TESTING] %level_name% in `email-notifications-command` command'); | ||
$message->setSubject("[TESTING] %level_name% in `{$name}` command"); | ||
$message->setFrom(to_swiftmailer_emails([ | ||
'address' => '[email protected]', | ||
'name' => 'ICLogger Notification', | ||
|