22
33namespace Illuminated \Console \ConsoleLogger \Tests \Loggable \Notifications \EmailChannel ;
44
5- use Monolog \Logger ;
65use EmailNotificationsCommand ;
7- use Monolog \Handler \MandrillHandler ;
8- use Monolog \Handler \SwiftMailerHandler ;
9- use Monolog \Handler \NativeMailerHandler ;
10- use Monolog \Handler \DeduplicationHandler ;
116use EmailNotificationsDeduplicationCommand ;
127use EmailNotificationsInvalidRecipientsCommand ;
138use Illuminated \Console \ConsoleLogger \Tests \TestCase ;
149use Illuminated \Console \Loggable \Notifications \EmailChannel \MonologHtmlFormatter ;
10+ use Monolog \Handler \DeduplicationHandler ;
11+ use Monolog \Handler \SwiftMailerHandler ;
12+ use Monolog \Logger ;
1513
1614class EmailChannelTest extends TestCase
1715{
@@ -22,16 +20,6 @@ public function it_validates_and_filters_notification_recipients()
2220 $ this ->assertNotInstanceOf (SwiftMailerHandler::class, $ handler );
2321 }
2422
25- /** @test */
26- public function it_is_disabled_on_null_driver ()
27- {
28- config (['mail.driver ' => 'null ' ]);
29-
30- $ handler = $ this ->runArtisan (new EmailNotificationsCommand )->createEmailChannelHandler ();
31-
32- $ this ->assertFalse ($ handler );
33- }
34-
3523 /** @test */
3624 public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver ()
3725 {
@@ -59,81 +47,34 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driv
5947 $ this ->assertMailerHandlersEqual ($ this ->composeSwiftMailerHandler (), $ handler );
6048 }
6149
62- /** @test */
63- public function it_uses_configured_monolog_mandrill_mailer_handler_on_mandrill_driver ()
64- {
65- config (['mail.driver ' => 'mandrill ' , 'services.mandrill.secret ' => 'secret ' ]);
66- $ handler = $ this ->runArtisan (new EmailNotificationsCommand )->emailChannelHandler ();
67-
68- $ this ->assertMailerHandlersEqual ($ this ->composeMandrillMailerHandler (), $ handler );
69- }
70-
71- /** @test */
72- public function it_uses_configured_monolog_native_mailer_handler_on_other_drivers ()
73- {
74- config (['mail.driver ' => 'any-other ' ]);
75- $ handler = $ this ->runArtisan (new EmailNotificationsCommand )->emailChannelHandler ();
76-
77- $ this ->assertMailerHandlersEqual ($ this ->composeNativeMailerHandler (), $ handler );
78- }
79-
8050 /** @test */
8151 public function it_uses_configured_monolog_deduplication_handler_if_deduplication_enabled ()
8252 {
83- config (['mail.driver ' => 'any-other ' ]);
53+ config (['mail.driver ' => 'sendmail ' ]);
8454 $ handler = $ this ->runArtisan (new EmailNotificationsDeduplicationCommand )->emailChannelHandler ();
8555 $ handler ->flush ();
8656
8757 $ this ->assertMailerHandlersEqual ($ this ->composeDeduplicationHandler (), $ handler );
8858 }
8959
90- private function composeSwiftMailerHandler ()
60+ private function composeSwiftMailerHandler ($ name = ' email-notifications-command ' )
9161 {
92- $ handler = new SwiftMailerHandler (app ('swift.mailer ' ), $ this ->composeMailerHandlerMessage (), Logger::NOTICE );
62+ $ handler = new SwiftMailerHandler (app ('swift.mailer ' ), $ this ->composeMailerHandlerMessage ($ name ), Logger::NOTICE );
9363 $ handler ->setFormatter (new MonologHtmlFormatter );
9464 return $ handler ;
9565 }
9666
97- private function composeMandrillMailerHandler ()
98- {
99- $ handler = new MandrillHandler (
100- config ('services.mandrill.secret ' ), $ this ->composeMailerHandlerMessage (), Logger::NOTICE
101- );
102- $ handler ->setFormatter (new MonologHtmlFormatter );
103- return $ handler ;
104- }
105-
106- private function composeNativeMailerHandler ($ name = 'email-notifications-command ' )
107- {
108- $ handler = new NativeMailerHandler (
109- to_rfc2822_email ([
110- [
'address ' =>
'[email protected] ' ,
'name ' =>
'John Doe ' ],
111- [
'address ' =>
'[email protected] ' ,
'name ' =>
'Jane Smith ' ],
112- ]),
113- "[TESTING] %level_name% in ` {$ name }` command " ,
114- to_rfc2822_email ([
115- 116- 'name ' => 'ICLogger Notification ' ,
117- ]),
118- Logger::NOTICE
119- );
120- $ handler ->setContentType ('text/html ' );
121- $ handler ->setFormatter (new MonologHtmlFormatter );
122-
123- return $ handler ;
124- }
125-
12667 private function composeDeduplicationHandler ()
12768 {
12869 return new DeduplicationHandler (
129- $ this ->composeNativeMailerHandler ('email-notifications-deduplication-command ' ), null , Logger::NOTICE , 60
70+ $ this ->composeSwiftMailerHandler ('email-notifications-deduplication-command ' ), null , Logger::NOTICE , 60
13071 );
13172 }
13273
133- private function composeMailerHandlerMessage ()
74+ private function composeMailerHandlerMessage ($ name = ' email-notifications-command ' )
13475 {
13576 $ message = app ('swift.mailer ' )->createMessage ();
136- $ message ->setSubject (' [TESTING] %level_name% in `email-notifications-command ` command ' );
77+ $ message ->setSubject (" [TESTING] %level_name% in ` { $ name } ` command " );
13778 $ message ->setFrom (to_swiftmailer_emails ([
1387913980 'name ' => 'ICLogger Notification ' ,
0 commit comments