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 sent and the first emails subject.

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

Post a Comment

Your email address is never published nor shared. Required fields are marked *

Ready to talk?

Whether you want to create a new digital product or make an existing one even better, we'd love to talk it through.

Get in touch