Skip to content

Commit f60eac8

Browse files
committed
[#2201] Adding index entries and minor tweaks for new email testing entry
1 parent ba88629 commit f60eac8

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

cookbook/email/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Email
88
gmail
99
dev_environment
1010
spool
11+
testing

cookbook/email/testing.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
.. index::
22
single: Emails; Testing
33

4-
How to functionally test an Email is sent
5-
=========================================
4+
How to test that an Email is sent in a functional Test
5+
======================================================
66

7-
Sending e-mails with Symfony2 is pretty straight forward thanks to the
7+
Sending e-mails with Symfony2 is pretty straightforward thanks to the
88
``SwiftmailerBundle``, which leverages the power of the `Swiftmailer`_ library.
99

10-
To functionally test that e-mails are sent, and even assert their subjects,
11-
content or any other headers we can use :ref:`the Symfony2 Profiler <internals-profiler>`.
10+
To functionally test that an email was sent, and even assert the email subject,
11+
content or any other headers, you can use :ref:`the Symfony2 Profiler <internals-profiler>`.
1212

13-
Let's start with an easy controller action that sends an e-mail::
13+
Start with an easy controller action that sends an e-mail::
1414

15-
public function indexAction($name)
15+
public function sendEmailAction($name)
1616
{
1717
$message = \Swift_Message::newInstance()
1818
->setSubject('Hello Email')
@@ -28,9 +28,10 @@ Let's start with an easy controller action that sends an e-mail::
2828

2929
.. note::
3030

31-
Don't forget to enable profiler as explained in :doc:`/cookbook/testing/profiling`.
31+
Don't forget to enable the profiler as explained in :doc:`/cookbook/testing/profiling`.
3232

33-
And the ``WebTestCase`` to assert the e-mail content should be similar to::
33+
In your functional test, use the ``swiftmailer`` collector on the profiler
34+
to get information about the messages send on the previous request::
3435

3536
// src/Acme/DemoBundle/Tests/Controller/MailControllerTest.php
3637
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@@ -40,7 +41,7 @@ And the ``WebTestCase`` to assert the e-mail content should be similar to::
4041
public function testMailIsSentAndContentIsOk()
4142
{
4243
$client = static::createClient();
43-
$crawler = $client->request('GET', 'your_action_route_here');
44+
$crawler = $client->request('POST', '/path/to/above/action');
4445

4546
$mailCollector = $client->getProfile()->getCollector('swiftmailer');
4647

@@ -59,3 +60,4 @@ And the ``WebTestCase`` to assert the e-mail content should be similar to::
5960
}
6061
}
6162

63+
.. _Swiftmailer: http://swiftmailer.org/

cookbook/map.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* :doc:`/cookbook/email/gmail`
6363
* :doc:`/cookbook/email/dev_environment`
6464
* :doc:`/cookbook/email/spool`
65+
* :doc:`/cookbook/email/testing`
6566

6667
* :doc:`/cookbook/event_dispatcher/index`
6768

@@ -139,6 +140,7 @@
139140
* :doc:`/cookbook/testing/profiling`
140141
* :doc:`/cookbook/testing/doctrine`
141142
* :doc:`/cookbook/testing/bootstrap`
143+
* (email) :doc:`/cookbook/email/testing`
142144

143145
* :doc:`/cookbook/validation/index`
144146

0 commit comments

Comments
 (0)