Skip to content

Commit fcdcae8

Browse files
committed
minor #16195 Add functional test chapter to mailer (famoser)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- Add functional test chapter to mailer Formulation largely from https://symfony.com/doc/4.4/email.html#how-to-test-that-an-email-is-sent-in-a-functional-test Simple example which showcases the "global" methods like `assertEmailCount` and the e-mail specific assertions. Taken from actual code in use, so should be close to what user wants to accomplish. Targets the 4.4 branch as described in the docs. Resolves #14397 Commits ------- da0b358 Add functional test chapter to mailer
2 parents 86a9d92 + da0b358 commit fcdcae8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

mailer.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,37 @@ a specific address, instead of the *real* address:
11211121
],
11221122
]);
11231123
1124+
Write a Functional Test
1125+
~~~~~~~~~~~~~~~~~~~~~~~
1126+
1127+
To functionally test that an email was sent, and even assert the email content or headers,
1128+
you can use the built in assertions::
1129+
1130+
// tests/Controller/MailControllerTest.php
1131+
namespace App\Tests\Controller;
1132+
1133+
use Symfony\Bundle\FrameworkBundle\Test\MailerAssertionsTrait;
1134+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1135+
1136+
class MailControllerTest extends WebTestCase
1137+
{
1138+
use MailerAssertionsTrait;
1139+
1140+
public function testMailIsSentAndContentIsOk()
1141+
{
1142+
$client = $this->createClient();
1143+
$client->request('GET', '/mail/send');
1144+
$this->assertResponseIsSuccessful();
1145+
1146+
$this->assertEmailCount(1);
1147+
1148+
$email = $this->getMailerMessage();
1149+
1150+
$this->assertEmailHtmlBodyContains($email, 'Welcome');
1151+
$this->assertEmailTextBodyContains($email, 'Welcome');
1152+
}
1153+
}
1154+
11241155
.. _`high availability`: https://en.wikipedia.org/wiki/High_availability
11251156
.. _`load balancing`: https://en.wikipedia.org/wiki/Load_balancing_(computing)
11261157
.. _`download the foundation-emails.css file`: https://github.com/foundation/foundation-emails/blob/develop/dist/foundation-emails.css

0 commit comments

Comments
 (0)