2
2
3
3
namespace rpkamp \Mailhog \Tests ;
4
4
5
- use RuntimeException ;
6
- use Swift_Mailer ;
7
- use Swift_Message ;
8
- use Swift_SmtpTransport ;
5
+ use Symfony \ Component \ Mailer \ Mailer ;
6
+ use Symfony \ Component \ Mailer \ MailerInterface ;
7
+ use Symfony \ Component \ Mailer \ Transport ;
8
+ use Symfony \ Component \ Mime \ Email ;
9
9
10
10
trait MessageTrait
11
11
{
12
12
/**
13
- * @var Swift_Mailer
13
+ * @var MailerInterface
14
14
*/
15
15
private $ mailer ;
16
16
@@ -21,29 +21,29 @@ public function sendDummyMessage(): void
21
21
);
22
22
}
23
23
24
- public function createDummyMessage (): Swift_Message
24
+ public function createDummyMessage (): Email
25
25
{
26
26
return $ this ->createBasicMessage ('me@myself.example ' , 'myself@myself.example ' , 'Hello ' , 'How are you? ' );
27
27
}
28
28
29
- public function createBasicMessage (string $ from , string $ to , string $ subject , string $ body ): Swift_Message
29
+ public function createBasicMessage (string $ from , string $ to , string $ subject , string $ body ): Email
30
30
{
31
- return (new Swift_Message ())
32
- ->setFrom ($ from )
33
- ->setTo ($ to )
34
- ->setSubject ($ subject )
35
- ->setBody ($ body );
31
+ return (new Email ())
32
+ ->from ($ from )
33
+ ->to ($ to )
34
+ ->subject ($ subject )
35
+ ->text ($ body );
36
36
}
37
37
38
- public function sendMessage (Swift_Message $ message ): void
38
+ public function sendMessage (Email $ message ): void
39
39
{
40
40
$ this ->getMailer ()->send ($ message );
41
41
}
42
42
43
- private function getMailer (): Swift_Mailer
43
+ private function getMailer (): MailerInterface
44
44
{
45
45
if (null === $ this ->mailer ) {
46
- $ this ->mailer = new Swift_Mailer ( new Swift_SmtpTransport (MailhogConfig:: getHost (), MailhogConfig:: getPort () ));
46
+ $ this ->mailer = new Mailer (Transport:: fromDsn ( $ _ENV [ ' mailhog_smtp_dsn ' ] ));
47
47
}
48
48
49
49
return $ this ->mailer ;
0 commit comments