News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Codeception.com:
Testing Emails in PHP. Part 1 PHPUnit
December 18, 2013 @ 13:04:05

On Codeception.com an tutorial has been posted showing you how to use PHPUnit to test emails - verifying that your application emails are being sent with the help of a third-party service.

So how do you check that your applications sends email correctly? It looks like dealing with emails is always a challenge. How would you verify that email message is formatted and delivered correctly, without actually sending them to your clients? That's the first question. And the second question is: how can we automate testing of emails? For both questions we have an answer.

To answer the first, they recommend using a service like Mailtrap or Mailcatcher (the one they use for the post) to receive the emails for evaluation. They help you get both PHPUnit and the popular Guzzle HTTP library installed to help with resting against Mailcatcher's REST API. The example test is also included, showing a few methods that connect to the API, get the most recent messages and clear the list when it's complete. Assertions like assertEmailIsSent, assertEmailHtmlContains and assertEmailSenderEquals show how to test the message results that come back for validity.

0 comments voice your opinion now!
test unittest phpunit email send mailcatcher rest api

Link: http://codeception.com/12-15-2013/testing-emails-in-php.html

blog comments powered by Disqus

Similar Posts

Mike Dalisay: Salt, Hash and Store Passwords Securely with Phpass

Sebastian Bergmann's Blog: Visualizing Text Differences in PHPUnit 3

Jeremy Cook's Blog: Making PHPUnit, Doctrine & MySQL Play Nicely

Benjamin Eberlei's Blog: Testing Database Locks with PHPUnit and Gearman

Matthew Weier O'Phinney's Blog: Zend Framework 1.6.0 Preview, or, PHP 4 is Dead


Community Events

Don't see your event here?
Let us know!


laravel introduction composer project programming php7 part2 list interview language api framework community example podcast symfony opinion application series yii2

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework