This document will be most useful for developers that want to contribute to WPGraphQL and want to run tests locally.
In order to run tests, you must clone the plugin from Github. Downloading from Composer or Packagist will not include the dev dependencies needed to run tests.
Running tests locally with Codeception is the fastest way to run tests, but it requires some initial setup on your local machine.
- Command line access
- PHP installed and running on your machine
- MySQL installed and running on your machine
WPGraphQL includes a script to install a local test environment.
Running this script will install WordPress to your machines
tmp directory, and will add WPGraphQL as a plugin and activate it.
NOTE: Because this installs to a tmp directory, if you restart your computer, this will go away so you would need to run this script again to setup your test environment again.
Run the following command, replacing the variables with data for your local Database
This should output similar to the following:
/tests/ directory of WPGraphQL are the Codeception
.yml configuration files.
To run tests locally, copy the
.yml file for the test suite you want to run and rename it without the
Then update the details of the
.yml file to point to your local database by changing the fields:
The other fields should be able to remain the same, but update as necessary.
Run the following script from the root of the WPGraphQL plugin:
This installs the dev dependencies needed to run the tests.
To run the tests, run the following commands (you can use
control + c to exit):
This will run all of the tests of the
To run an individual test file, you can specify the file like so:
Or you can specify one specific test like so:
The tests should start running and you should see something similar to the following:
Testing in docker is slower than testing locally with Codeception, but it allows you to test in a consistent environment and not have to worry about a local environment issue getting in the way of running the tests.
In order to run tests with Docker, you should have Docker running on your machine.
Build and start the Docker testing environment by running this command:
This step will take several minutes the first time it's run because it needs to install OS dependencies. This work will be cached so you won't have to wait as long the next time you run it. You are ready to go to the next step to run the full test suite in the docker container.
To run individual tests, you will need to build the ‘app' docker image.
In the terminal window, access the Docker container shell from which you can run tests:
You should eventually see a prompt like this:
Now you are ready to work in your IDE and test your changes by running any of the following commands in the second terminal window):
Use the environment variable SUITES to specify individual files or lists of files to test. This is useful when working on one test file and wanting to limit test execution to the single file or test. Also see the contributing documentation on enabling xdebug in the testing docker environment.
- If you make a change that requires
composer installto be rerun, run composter build-app again.
- Leave the container shell by typing
- Docker artifacts will usually be cleaned up automatically when the script completes. In case it doesn't do the job, try these solutions:
- Run this command:
docker system prune
- Run this command: