Functional testing sending emails in Silex

We are slowly starting to fall in love with Silex the Micro Framework built using Symfony2 here at White October towers.
Here is a quick code sample which shows how to test emails that are sent using Silex and Swiftmailer.
I would recommend using this example app to get Silex and Swiftmailer setup if you haven’t got a working setup.
The aim in the code is to stop sending of real email in the test environment and log the messages so we can test them.
Here is a quick gist of the Test class, testing for number of emails send and the first email subject.

I have copied out the Symfony2 MessageLogger.php class from the SwiftmailerBundle, which I’ve included in the gist for your convenience.

View the original article

Comments