Search code examples
phpemailphpunitimap

PHPUnit email testing


I have a PHPUnit test that does the following:

  • fill out a form on a web page using Selenium RC
  • (The app sends an email to a gmail account)
  • connect to the gmail account with imap_open()
  • verify that certain strings exist in the email

My problem is that my test is failing randomly because I'm not waiting for the email to be sent. What would you do in this situation?


Solution

  • Don't use an external mailserver. Set up fakemail. The Python version is easier to use. http://fakemail.sourceforge.net/

    I've used fakemail for quite some time and it makes my php simpletest tests run very fast (no external latency), and they're 100% repeatable.

    I retain a different set of tests if I want to actually test the mail sending part of my script. In my eyes, the 'checking that strings are there' and 'checking that email got sent to gmail' are two different failure points, and should be split into different tests.