I am trying to write automated tests for a or that will sent an email on submission.
I can write the test to check for the presence of the entity that is created along side the email, but I also want to have my automated test check that the system is sending an email too.

The examples I can find seem to relate to Laravel and the use of spies to see if a particular class method is called, however I can't find any examples of how to do that in Drupal 8 and in my particular use case I am using the function _user_mail_notify() and not a class method.

Does anyone have an example of testing that emails have seen sent at all?

1 Answer 1


Look at core tests that utilize email. For example:

The tests demonstrate ways to inspect the plugin.manager.mail service for signs that mail was successfully sent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.