I have a PHPUnit test that does the following:
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?
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.