Videos
Check out our tutorial video series.
How to Test User Sign Up with Real Emails using Codeception and MailSlurp for PHP Applications
If you write PHP applications then you've probably heard of Codeception - a comprehensive acceptance testing framework for PHP. With Codeception you can test applications written in Laravel, Symfony, Wordpress and more using automated browsers. With the addition of MailSlurp you can test user behavior like sign-up and password reset using real email addresses. MailSlurp is a free PHP library that let's you create test email accounts on demand and the send and receive emails and attachments from code and tests. This post will show you how to test user sign up with real emails using a simple demonstration app.
See full example code on GitHub
We will use a basic React App hosted at playground.mailslurp.com to demonstrate Codeception and MailSlurp behavior. This web app has a common authentication flow:
Codeception is easier to install using Composer. First, create a new directory:
Next, install Composer by running the following script:
This will create a file in our directory.
Codeception runs acceptance tests in real browsers. For this test we will use Selenium to driver Firefox. We need to download the Selenium Standalone Server jar and a Geckodriver binary.
To download Selenium run the following command:
Note you will need Java installed to run the server during tests.
To automate testing with Firefox and Selenium we need a Geckodriver. This script will install it locally for linux machines. For other platforms see the releases page.
Now we can specify our dependencies in a file. We will need Codeception for acceptance testing and MailSlurp for creating emails:
Next run to install the dependencies locally.
Codeception comes with many helpful commands. We can use the vendored dependency to scaffold our app.
This will create a `codeception.yml' file plus a number of test directories:
Edit the file to add the playground url and configure the AcceptanceTester actor. The end result should look like this:
Next edit and add configure Selenium and Geckodriver to run before tests run:
To test user sign up in our tests we will create test email accounts for each user. MailSlurp is free but you need to an API Key to configure the client.
Create a free account to get your API Key.
Codeception using the term for tests. Let's create one for testing user sign up in our playground app. Again we can use the Codeception dependency in the command line:
Let's add some basic methods.
To test our application loads in Firefox let's write a basic test method:
We can run our initial test with . We should see passing tests with the output:
Now that we have setup some tests and seen how to run them let's test the entire user sign up process end-to-end using a test email account.
We can create real emails in tests using MailSlurp's InboxControllerApi:
An inbox has an and an
property. We will use them to sign up a user.
We can sign up a user by loading the playground app and submitting the email address and a test password:
Next we can wait for the user to receive a confirmation email and parse the verification code from the body:
Once extracted we can use the code to confirm the user.
After successfully confirming a user we can login and see a picture of a happy dog. Let's do that:
By running we should see an automated sign up and confirmation
Codeception is a powerful framework for writing end-to-end acceptance tests in PHP. It used with Laravel, Symfony, Wordpress and many other application. By combining Codeception with MailSlurp we can test applications using real email addresses. As you can see in the example above we were able to create real email accounts for each test user and receive confirmation codes. Use MailSlurp and Codeception today to test your own application. Sign up now.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.