88use Illuminated \Console \Tests \App \Console \Commands \EmailNotificationsInvalidRecipientsCommand ;
99use Illuminated \Console \Tests \TestCase ;
1010use Monolog \Handler \DeduplicationHandler ;
11- use Monolog \Handler \NativeMailerHandler ;
1211use Monolog \Handler \SwiftMailerHandler ;
1312use Monolog \Logger ;
1413use Swift_Message ;
@@ -23,17 +22,6 @@ public function it_validates_and_filters_notification_recipients()
2322 $ this ->assertNotInstanceOf (SwiftMailerHandler::class, $ command ->emailChannelHandler ());
2423 }
2524
26- /** @test */
27- public function it_is_disabled_on_null_driver ()
28- {
29- config (['mail.driver ' => 'null ' ]);
30-
31- /** @var EmailNotificationsCommand $command */
32- $ command = $ this ->runArtisan (new EmailNotificationsCommand );
33-
34- $ this ->assertFalse ($ command ->createEmailChannelHandler ());
35- }
36-
3725 /** @test */
3826 public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver ()
3927 {
@@ -71,21 +59,10 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driv
7159 $ this ->assertMailerHandlersEqual ($ this ->composeSwiftMailerHandler (), $ command ->emailChannelHandler ());
7260 }
7361
74- /** @test */
75- public function it_uses_configured_monolog_native_mailer_handler_on_other_drivers ()
76- {
77- config (['mail.driver ' => 'any-other ' ]);
78-
79- /** @var EmailNotificationsCommand $command */
80- $ command = $ this ->runArtisan (new EmailNotificationsCommand );
81-
82- $ this ->assertMailerHandlersEqual ($ this ->composeNativeMailerHandler (), $ command ->emailChannelHandler ());
83- }
84-
8562 /** @test */
8663 public function it_uses_configured_monolog_deduplication_handler_if_deduplication_enabled ()
8764 {
88- config (['mail.driver ' => 'any-other ' ]);
65+ config (['mail.driver ' => 'sendmail ' ]);
8966
9067 /** @var EmailNotificationsDeduplicationCommand $command */
9168 $ command = $ this ->runArtisan (new EmailNotificationsDeduplicationCommand );
@@ -98,43 +75,18 @@ public function it_uses_configured_monolog_deduplication_handler_if_deduplicatio
9875 /**
9976 * Compose "swift mailer" handler.
10077 *
78+ * @param string $command
10179 * @return \Monolog\Handler\SwiftMailerHandler
10280 */
103- private function composeSwiftMailerHandler ()
81+ private function composeSwiftMailerHandler ($ command = ' email-notifications-command ' )
10482 {
105- $ handler = new SwiftMailerHandler (app ('mailer ' )->getSwiftMailer (), $ this ->composeMailerHandlerMessage (), Logger::NOTICE );
83+ $ handler = new SwiftMailerHandler (app ('mailer ' )->getSwiftMailer (), $ this ->composeMailerHandlerMessage ($ command ), Logger::NOTICE );
10684
10785 $ handler ->setFormatter (new MonologHtmlFormatter );
10886
10987 return $ handler ;
11088 }
11189
112- /**
113- * Compose "native mailer" handler.
114- *
115- * @param string $name
116- * @return \Monolog\Handler\NativeMailerHandler
117- */
118- private function composeNativeMailerHandler (string $ name = 'email-notifications-command ' )
119- {
120- $ handler = new NativeMailerHandler (
121- to_rfc2822_email ([
122- [
'address ' =>
'[email protected] ' ,
'name ' =>
'John Doe ' ],
123- [
'address ' =>
'[email protected] ' ,
'name ' =>
'Jane Smith ' ],
124- ]),
125- "[TESTING] %level_name% in ` {$ name }` command " ,
126- to_rfc2822_email ([
127- 128- 'name ' => 'ICLogger Notification ' ,
129- ]),
130- Logger::NOTICE
131- );
132- $ handler ->setContentType ('text/html ' );
133- $ handler ->setFormatter (new MonologHtmlFormatter );
134-
135- return $ handler ;
136- }
137-
13890 /**
13991 * Compose "deduplication" handler.
14092 *
@@ -143,20 +95,21 @@ private function composeNativeMailerHandler(string $name = 'email-notifications-
14395 private function composeDeduplicationHandler ()
14496 {
14597 return new DeduplicationHandler (
146- $ this ->composeNativeMailerHandler ('email-notifications-deduplication-command ' ), null , Logger::NOTICE , 60
98+ $ this ->composeSwiftMailerHandler ('email-notifications-deduplication-command ' ), null , Logger::NOTICE , 60
14799 );
148100 }
149101
150102 /**
151103 * Compose mailer handler message.
152104 *
105+ * @param string $command
153106 * @return \Swift_Message
154107 */
155- private function composeMailerHandlerMessage ()
108+ private function composeMailerHandlerMessage ($ command )
156109 {
157110 /** @var Swift_Message $message */
158111 $ message = app ('mailer ' )->getSwiftMailer ()->createMessage ();
159- $ message ->setSubject (' [TESTING] %level_name% in `email-notifications- command` command ' );
112+ $ message ->setSubject (" [TESTING] %level_name% in ` { $ command} ` command " );
160113 $ message ->setFrom (to_swiftmailer_emails ([
161114162115 'name ' => 'ICLogger Notification ' ,
0 commit comments