Skip to content

Commit dafb05c

Browse files
authored
Merge pull request #55 from rpkamp/symfony-mailer
Replace deprecated SwiftMailer with Symfony Mailer
2 parents 4ed812d + f483794 commit dafb05c

File tree

3 files changed

+104
-140
lines changed

3 files changed

+104
-140
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"phpmd/phpmd": "^2.9.1",
3434
"phpunit/phpunit": "^8.0",
3535
"php-http/curl-client": "^2.0",
36-
"swiftmailer/swiftmailer": "6.2.3",
3736
"phpstan/phpstan": "^0.12.64",
3837
"pdepend/pdepend": "^2.5",
3938
"nyholm/psr7": "^1.2",
4039
"doctrine/coding-standard": "^8.0",
4140
"php-parallel-lint/php-parallel-lint": "^1.2",
42-
"egulias/email-validator": "^2.1.23"
41+
"egulias/email-validator": "^2.1.23",
42+
"symfony/mailer": "^5.0"
4343
}
4444
}

tests/MessageTrait.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace rpkamp\Mailhog\Tests;
44

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;
99

1010
trait MessageTrait
1111
{
1212
/**
13-
* @var Swift_Mailer
13+
* @var MailerInterface
1414
*/
1515
private $mailer;
1616

@@ -21,29 +21,29 @@ public function sendDummyMessage(): void
2121
);
2222
}
2323

24-
public function createDummyMessage(): Swift_Message
24+
public function createDummyMessage(): Email
2525
{
2626
return $this->createBasicMessage('me@myself.example', 'myself@myself.example', 'Hello', 'How are you?');
2727
}
2828

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
3030
{
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);
3636
}
3737

38-
public function sendMessage(Swift_Message $message): void
38+
public function sendMessage(Email $message): void
3939
{
4040
$this->getMailer()->send($message);
4141
}
4242

43-
private function getMailer(): Swift_Mailer
43+
private function getMailer(): MailerInterface
4444
{
4545
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']));
4747
}
4848

4949
return $this->mailer;

0 commit comments

Comments
 (0)