Skip to content

Commit

Permalink
Merge pull request #55 from rpkamp/symfony-mailer
Browse files Browse the repository at this point in the history
Replace deprecated SwiftMailer with Symfony Mailer
  • Loading branch information
rpkamp authored Feb 18, 2022
2 parents 4ed812d + f483794 commit dafb05c
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 140 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"phpmd/phpmd": "^2.9.1",
"phpunit/phpunit": "^8.0",
"php-http/curl-client": "^2.0",
"swiftmailer/swiftmailer": "6.2.3",
"phpstan/phpstan": "^0.12.64",
"pdepend/pdepend": "^2.5",
"nyholm/psr7": "^1.2",
"doctrine/coding-standard": "^8.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"egulias/email-validator": "^2.1.23"
"egulias/email-validator": "^2.1.23",
"symfony/mailer": "^5.0"
}
}
30 changes: 15 additions & 15 deletions tests/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace rpkamp\Mailhog\Tests;

use RuntimeException;
use Swift_Mailer;
use Swift_Message;
use Swift_SmtpTransport;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Email;

trait MessageTrait
{
/**
* @var Swift_Mailer
* @var MailerInterface
*/
private $mailer;

Expand All @@ -21,29 +21,29 @@ public function sendDummyMessage(): void
);
}

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

public function createBasicMessage(string $from, string $to, string $subject, string $body): Swift_Message
public function createBasicMessage(string $from, string $to, string $subject, string $body): Email
{
return (new Swift_Message())
->setFrom($from)
->setTo($to)
->setSubject($subject)
->setBody($body);
return (new Email())
->from($from)
->to($to)
->subject($subject)
->text($body);
}

public function sendMessage(Swift_Message $message): void
public function sendMessage(Email $message): void
{
$this->getMailer()->send($message);
}

private function getMailer(): Swift_Mailer
private function getMailer(): MailerInterface
{
if (null === $this->mailer) {
$this->mailer = new Swift_Mailer(new Swift_SmtpTransport(MailhogConfig::getHost(), MailhogConfig::getPort()));
$this->mailer = new Mailer(Transport::fromDsn($_ENV['mailhog_smtp_dsn']));
}

return $this->mailer;
Expand Down
Loading

0 comments on commit dafb05c

Please sign in to comment.