This is a library that provides a ready to use instance of PHPUNIT for unit testing in a wordpress environment. It uses Yoast/PHPUnit-Polyfills which allows it to run on any PHP version.
- Working install of Wordpress.
- An empty database for testing.
- PHPUNIT must be installed on your system.
- Composer must be installed on your system.
- Copy
wp-test-libto wherever you'd like. - Open
wp-test-libin a terminal and runcomposer update. This will install all of the dependencies. - Copy
/teststo wherever you'd like your unit tests to reside. - Modify
/tests/wp-tests-config.phpto setup your test DB credentials. Keep in mind, this should be an empty database. Any data in this database will be destroyed every time the tests conclude. Do not use a production database. - Modify
/tests/boot.phpand setup any global options. You will also need to modify this file to point to thewp-test-lib/bootstrap.phpfile in whatever location you put it. - Modify
/tests/phpunit.xmlto add your test suites. - Look at
/tests/test-suite-1/test-1.phpfor an example on how to create unit tests
To run your tests, open your /tests/ directory in a command line and run phpunit