This repository is a test base for setting up unit testing of wordpress theme and plugins.
- A development environment for WordPress application development, LAMP , WAMP, MAMP, XAMPP all supported , But best results can be achieved with virtual machines eg. https://github.com/Varying-Vagrant-Vagrants/VVV
- PHPUnit latest version installed. Please check this link for help https://phpunit.de/getting-started.html
- A blank mysql database and database user
- Shell or Terminal access to execute command line tools.
-
Clone the current repository and place in the web server root directory of your development environment.
-
Copy wp-test-config-sample.php and create a file wp-test-config.php
-
Update wp-test-config.php
define( 'WP_DEFAULT_THEME', ‘your-default-theme' );
define( 'WP_DEFAULT_THEME_DIR', ‘your-wordpress-theme-directory-path' );
Please provide the full path of the theme directory which is to be unit tested in WP_DEFAULT_THEME_DIR.
Update the database details for testing , Never use your production database for testing , it will be wiped out. Please use a separate blank database for testing
define( 'DB_NAME', 'youremptytestdbnamehere' );
define( 'DB_USER', 'yourusernamehere' );
define( 'DB_PASSWORD', 'yourpasswordhere' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
Update other details in wp-config-test.php if required.
-
Update phpunit.xml.dist
Update the file path to point out the directory with unit test cases placed for your plugin or theme
tests/phpunit/tests ….update the path on above line , replacing "tests/phpunit/tests” with your test files.
Go to the root of repository and execute “phpunit” to see the test results
e.g. i-mac: wordpress-develop my-user$ phpunit
https://phpunit.de/getting-started.html
https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/