Skip to content

Add functional test chapter to mailer #16195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,37 @@ a specific address, instead of the *real* address:
],
]);

Write a Functional Test
~~~~~~~~~~~~~~~~~~~~~~~

To functionally test that an email was sent, and even assert the email content or headers,
you can use the built in assertions::

// tests/Controller/MailControllerTest.php
namespace App\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\MailerAssertionsTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MailControllerTest extends WebTestCase
{
use MailerAssertionsTrait;

public function testMailIsSentAndContentIsOk()
{
$client = $this->createClient();
$client->request('GET', '/mail/send');
$this->assertResponseIsSuccessful();

$this->assertEmailCount(1);

$email = $this->getMailerMessage();

$this->assertEmailHtmlBodyContains($email, 'Welcome');
$this->assertEmailTextBodyContains($email, 'Welcome');
}
}

.. _`high availability`: https://en.wikipedia.org/wiki/High_availability
.. _`load balancing`: https://en.wikipedia.org/wiki/Load_balancing_(computing)
.. _`download the foundation-emails.css file`: https://github.com/foundation/foundation-emails/blob/develop/dist/foundation-emails.css
Expand Down