Standards - Setting up integration tests for the plugins

When running integration tests we have to set up some WordPress Docker containers. This allows us to test against WordPress, which is the 'integration' part. An added bonus of this is that you also have a separate setup for writing patches and unit tests.

Clone the repository

Clone WordPress/wordpress-develop.

Expose MySQL port

After cloning has been done, you have to expose the MySQL port, which allows us to connect to it later on.

In wordpress-develop, open the docker-compose.yml file and change:

- "3306"

into

- "3306:3306"

This will expose the port to the local environment.

Edit your hosts file

Edit your hosts file by running sudo nano /etc/hosts in your terminal and add the following:

127.0.0.1 localhost
10.254.254.254 mysql

Making your database accessible

To make your database accessible, run the following command:

sudo ifconfig lo0 alias 10.254.254.254

Tying it all together

The last step is to tie it together with your wordpress-seo cloned repository. To do this, you'll have to define two environment variables:

  • WP_DEVELOP_DIR - Refers to the cloned repository of wordpress-develop, as it's located on your system.
  • WP_PLUGIN_DIR - Refers to the directory where the WordPress plugins are located.

Example:

WP_DEVELOP_DIR=/Users/andy/Documents/Development/wordpress-develop/
WP_PLUGIN_DIR=/Users/andy/Documents/Development/plugin-development-docker/plugins
Note the trailing slash in `WP_DEVELOP_DIR` and the absence of it in `WP_PLUGIN_DIR`.

Set up PHPUnit

If you have `WP_DEVELOP_DIR` and `WP_PLUGIN_DIR` as environment variables, you can skip this section.

Configure your PHPUnit configuration in PhpStorm by going to Edit Configurations... -> PHPUnit and ensure it looks similar to the following screenshot:

Spin up the containers

If you've gone through all the above steps, it's time to start the containers!

In your terminal, run the following commands:

npm install
npm run build:dev
npm run env:start
npm run env:install

When you want to stop the containers, you simply can do:

npm run env:stop

Troubleshooting

If you get errors about the database connection, make sure other no MySQL processes are running in the background by running brew services stop mysql in your terminal.