8
8
use Illuminated \Console \Tests \App \Console \Commands \EmailNotificationsInvalidRecipientsCommand ;
9
9
use Illuminated \Console \Tests \TestCase ;
10
10
use Monolog \Handler \DeduplicationHandler ;
11
- use Monolog \Handler \NativeMailerHandler ;
12
11
use Monolog \Handler \SwiftMailerHandler ;
13
12
use Monolog \Logger ;
14
13
use Swift_Message ;
@@ -23,17 +22,6 @@ public function it_validates_and_filters_notification_recipients()
23
22
$ this ->assertNotInstanceOf (SwiftMailerHandler::class, $ command ->emailChannelHandler ());
24
23
}
25
24
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
-
37
25
/** @test */
38
26
public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver ()
39
27
{
@@ -71,21 +59,10 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driv
71
59
$ this ->assertMailerHandlersEqual ($ this ->composeSwiftMailerHandler (), $ command ->emailChannelHandler ());
72
60
}
73
61
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
-
85
62
/** @test */
86
63
public function it_uses_configured_monolog_deduplication_handler_if_deduplication_enabled ()
87
64
{
88
- config (['mail.driver ' => 'any-other ' ]);
65
+ config (['mail.driver ' => 'sendmail ' ]);
89
66
90
67
/** @var EmailNotificationsDeduplicationCommand $command */
91
68
$ command = $ this ->runArtisan (new EmailNotificationsDeduplicationCommand );
@@ -98,43 +75,18 @@ public function it_uses_configured_monolog_deduplication_handler_if_deduplicatio
98
75
/**
99
76
* Compose "swift mailer" handler.
100
77
*
78
+ * @param string $name
101
79
* @return \Monolog\Handler\SwiftMailerHandler
102
80
*/
103
- private function composeSwiftMailerHandler ()
81
+ private function composeSwiftMailerHandler ($ name = ' email-notifications-command ' )
104
82
{
105
- $ handler = new SwiftMailerHandler (app ('mailer ' )->getSwiftMailer (), $ this ->composeMailerHandlerMessage (), Logger::NOTICE );
83
+ $ handler = new SwiftMailerHandler (app ('mailer ' )->getSwiftMailer (), $ this ->composeMailerHandlerMessage ($ name ), Logger::NOTICE );
106
84
107
85
$ handler ->setFormatter (new MonologHtmlFormatter );
108
86
109
87
return $ handler ;
110
88
}
111
89
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
-
138
90
/**
139
91
* Compose "deduplication" handler.
140
92
*
@@ -143,20 +95,21 @@ private function composeNativeMailerHandler(string $name = 'email-notifications-
143
95
private function composeDeduplicationHandler ()
144
96
{
145
97
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
147
99
);
148
100
}
149
101
150
102
/**
151
103
* Compose mailer handler message.
152
104
*
105
+ * @param string $name
153
106
* @return \Swift_Message
154
107
*/
155
- private function composeMailerHandlerMessage ()
108
+ private function composeMailerHandlerMessage ($ name = ' email-notifications-command ' )
156
109
{
157
110
/** @var Swift_Message $message */
158
111
$ message = app ('mailer ' )->getSwiftMailer ()->createMessage ();
159
- $ message ->setSubject (' [TESTING] %level_name% in `email-notifications-command ` command ' );
112
+ $ message ->setSubject (" [TESTING] %level_name% in ` { $ name } ` command " );
160
113
$ message ->setFrom (to_swiftmailer_emails ([
161
114
162
115
'name ' => 'ICLogger Notification ' ,
0 commit comments