Testing (Quick-Start Guide)
Until the documentation is in full effect, it's recommended that a GraphiQL-based tool like WPGraphiQL be used to view the GraphQL schema, an alternative to this is viewing the unit tests located in
tests/wpunit directory. Which are constantly updated along with the project. If you're interested in contributing when I begin accepting contribution or simply want to run the tests. Follow the instruction below.
Make sure all dependencies are install by running
composer installfrom the CMD/Terminal in the project directory.
Next the copy 2 distributed files with the
.distin there filenames. For instance
wpunit.suite.yml. The distributed files and what their copied names should are as follows.
.envand alter to make you usage.# docker ENV variablesDB_NAME=wordpressDB_HOST=app_dbDB_USER=wordpressDB_PASSWORD=wordpressWP_TABLE_PREFIX=wp_WP_URL=http://localhostWP_DOMAIN=localhostADMIN_EMAILfirstname.lastname@example.orgADMIN_USERNAME=adminADMIN_PASSWORD=passwordADMIN_PATH=/wp-admin# local codeception/install-wp-tests ENV variablesTEST_DB_NAME=woographql_testsTEST_DB_HOST=127.0.0.1TEST_DB_USER=wordpressTEST_DB_PASSWORD=wordpressTEST_WP_TABLE_PREFIX=wp_# install-wp-tests ENV variablesSKIP_DB_CREATE=falseTEST_WP_ROOT_FOLDER=/tmp/wordpressTEST_ADMIN_EMAILemail@example.com# codeception ENV variablesTESTS_DIR=testsTESTS_OUTPUT=tests/_outputTESTS_DATA=tests/_dataTESTS_SUPPORT=tests/_supportTESTS_ENVS=tests/_envs
docker ENV variables: variables defined for use in the Docker/Docker-Compose setups. These are also used in
codeception.dist.ymlfor testing within a Docker container. It's recommend that this file be left unchanged and a
codeception.ymlbe created for local codeception unit testing.
local codeception/install-wp-tests ENV variables: variable defined for use with codeception testing w/o docker and the
install-wp-testsscript in the
bindirectory. As mentioned above a
codeception.ymlshould be created from
codeception.dist.ymland the variables in the
WPLoaderconfig should be set accordingly.
install-wp-tests ENV variables: variables specific to the
install-wp-testsscript. The script can be run using
composer install-wp-testsin the terminal from project directory.
codeception ENV variables: variables used by codeception. This includes within the docker container as well.
Once you have finish modifying the
composer install-wp-testsfrom the project directory.
Upon success you can begin running the tests.
To run test use the command
vendor/bin/codecept run [suite [test [:test-function]]].
If you use the command with at least a
suite specified, Codeception will run all tests, however this is not recommended. Running a suite
vendor/bin/codecept run wpunit or a test
vendor/bin/codecept run CouponQueriesTest is recommended. Running a single
vendor/bin/codecept run ProductQueriesTest:testProductsQueryAndWhereArgs is also possible.
To learn more about the usage of Codeception with WordPress view the Documentation
Functional and Acceptance Tests (Docker & Docker-Compose Required)
It's possible to run functional and acceptance tests, but is very limited at the moment. The script docker entrypoint script runs all three suites (acceptance, functional, and wpunit) at once. This will change eventually, however as of right now, this is the limitation.
Even though the two suites use a Docker environment to run, the
testing service in the
docker.compose.yml file requires the
Run the following in the terminal to run all three suites. Isolating specific suites should be simple to figure out.
docker-compose run --rm \-e SUITES=acceptance;wpunit;functional \-e DEBUG=1 -e COVERAGE=1 testing --scale app=0
DEBUGvars are optional flags for toggle codecoverage and debug output.
--scale app=0ensures that the service running a local app doesn't create any instances. It must be added or a collision with
mysqlwill occur. More on this service in the next section
Using Docker-Compose to Run a Local Installation for Live Testing.
This is rather simple just like with testing using docker ensure that
codeception.dist.yml are untouched.
docker-compose up --scale testing=0 app
- wait for
app_1 | Success: Exported to '/var/www/html/wp-content/plugins/wp-graphql-woocommerce/tests/_data/dump.sql'.to print to the terminal.
- navigate to
http://localhost:8091. And that's it. You can view the configuration for the installation in the
docker-compose.yml. NOTE: if you get redirected to
docker-compose downto remove any existing containers related to the project, then re-run Step 1.
- For more information about the docker-image uses in the service, it's on Docker Hub.