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.env.distbecomes.envandwpunit.suite.dist.ymlbecomeswpunit.suite.yml. The distributed files and what their copied names should are as follows.codeception.dist.yml=>codeception.yml.env.dist=>.env
-
Next open
.envand alter to make you usage.# docker ENV variables DB_NAME=wordpress DB_HOST=app_db DB_USER=wordpress DB_PASSWORD=wordpress WP_TABLE_PREFIX=wp_ WP_URL=http://localhost WP_DOMAIN=localhost ADMIN_EMAIL=admin@example.com ADMIN_USERNAME=admin ADMIN_PASSWORD=password ADMIN_PATH=/wp-admin # local codeception/install-wp-tests ENV variables TEST_DB_NAME=woographql_tests TEST_DB_HOST=127.0.0.1 TEST_DB_USER=wordpress TEST_DB_PASSWORD=wordpress TEST_WP_TABLE_PREFIX=wp_ # install-wp-tests ENV variables SKIP_DB_CREATE=false TEST_WP_ROOT_FOLDER=/tmp/wordpress TEST_ADMIN_EMAIL=admin@wp.test # codeception ENV variables TESTS_DIR=tests TESTS_OUTPUT=tests/_output TESTS_DATA=tests/_data TESTS_SUPPORT=tests/_support TESTS_ENVS=tests/_envsdocker ENV variables: variables defined for use in the Docker/Docker-Compose setups. These are also used incodeception.dist.ymlfor testing within a Docker container. It's recommend that this file be left unchanged and acodeception.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 theinstall-wp-testsscript in thebindirectory. As mentioned above acodeception.ymlshould be created fromcodeception.dist.ymland the variables in theWPLoaderconfig should be set accordingly.install-wp-tests ENV variables: variables specific to theinstall-wp-testsscript. The script can be run usingcomposer 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
.envfile. Runcomposer 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 test-function like vendor/bin/codecept run ProductQueriesTest:testProductsQueryAndWhereArgs is also possible.
To learn more about the usage of Codeception with WordPress view the Documentation
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 .env.dist and codeception.dist.yml untouched.
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
- The
COVERAGE, andDEBUGvars 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 withmysqlwill occur. More on this service in the next section
This is rather simple just like with testing using docker ensure that env.dist and codeception.dist.yml are untouched.
- Run
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 http://localhost run docker-compose down to 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.