Closed
Description
Symfony version(s) affected: 5.2.0
Description
In a functionnal test, I get an error when I try to test that an email has been sent with mailer
How to reproduce
<?php
namespace App\Tests\Unit\Manager;
use App\Manager\EmailManager;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\FrameworkBundle\Test\MailerAssertionsTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
class EmailManagerTest extends KernelTestCase
{
use MailerAssertionsTrait;
private $mailer;
protected function setUp(): void
{
self::bootKernel();
$this->mailer = self::$container->get('mailer.mailer');
}
public function testSendEmail()
{
$emailManager = new EmailManager(
$this->createMock(LoggerInterface::class),
$this->mailer
);
$fromEmail = '[email protected]';
$fromName = 'dev from';
$from = new Address($fromEmail, $fromName);
$to = '[email protected]';
$subject = 'test subject';
$body = 'My own test body';
$emailManager->sendEmail(
$from,
$to,
$subject,
$body
);
$this->assertEmailCount(1); // error
}
}
Possible Solution
no idea
Additional context
the error I get is :
A client must have Mailer enabled to make email assertions. Did you forget to require symfony/mailer?
/srv/app/vendor/symfony/framework-bundle/Test/MailerAssertionsTrait.php:129
/srv/app/vendor/symfony/framework-bundle/Test/MailerAssertionsTrait.php:25