The WordPress coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. development team builds WordPress! Follow this site for general updates, status reports, and the occasional code debate. There’s lots of ways to contribute:
Found a bugbugA bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority.?Create a ticket in our bug tracker.
PHPUnit is the official testing framework chosen by the coreCoreCore is the set of software required to run WordPress. The Core Development Team builds WordPress. team to test our PHPPHPThe web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher code.
1. Install PHPUnit. WordPress uses PHPUnit, the standard for unit testing PHP projects. Installation instructions can be found in the PHPUnit manual or on the PHPUnit Github repository. Note: The latest release of PHPUnit is 8.x, WordPress is currently only compatible with the 7.x release tree. Until #46149 is merged, the latest PHPUnit 7.x release should be used:
Note: Multibyte String support (php-mbstring) needs to be installed to run PHPUnit tests.
2. Check out the test repository. The WordPress tests live in the core development repository, available via SVN at:
svn co https://develop.svn.wordpress.org/trunk/ wordpress-develop cd wordpress-develop
Or Git:
git clone git://develop.git.wordpress.org/ wordpress-develop
cd wordpress-develop
3. Create an empty MySQL database. The test suite will delete all data from all tables for whichever MySQL database it is configured. Use a separate database.
4. Set up a config file. Copy wp-tests-config-sample.php to wp-tests-config.php, and enter your database credentials. Use a separate database.
Note that the tests run from the build folder, so you need to build before testing, and run build watch to keep the build updated when testing changes.
First ensure Node is installed (which includes npm). In the root directory – next to the tests folder – run:
npm install
Grunt build or watch to sync changes from src to build:
npm run grunt build
npm run grunt watch
Finally, to run the tests:
phpunit
You should see output that looks roughly like the following:
Many tests are marked with a @ticket annotation, which indicates they were the result of that WordPress Trac ticket. The test is skipped if the ticket is still open – in these cases, we treat the test as a “known bug” that will likely fail.
To forcibly run the skipped tests for an open ticket, you may specify that ticket as a group:
Rather than having to switch to a terminal and manually run a test group repeatedly while working on a patch, you can keep it running continuously. Whenever you save any file, the group will run again automatically. This lets you instantly know when a change you’ve made breaks a test, or causes it to pass.
To run PHPUnit tests and all other watch tasks, use:
npm run grunt watch -- --phpunit --group={testgroup}
To run only the PHPUnit watch task, use:
npm run grunt watch:phpunit -- --group={testgroup}
Run multiple groups by comma-separating them:
npm run grunt watch:phpunit -- --group=community-events,privacy
You can speed up the suite in some cases by defining the WP_TESTS_SKIP_INSTALL environment variable to 1, so that the suite will skip the install step. While this shouldn’t be used for full test runs, it’s useful for saving time when running small groups of tests.
Write tests for a reported bug. A great way to contribute is to write tests that demonstrate an existing bug report. The core developers are reluctant to consider patches for many sensitive areas in core without test coverage. Well-written tests can help confirm that a patch fixes a problem without side effects, and can prevent any regressions from occurring in the future. When tests are particularly needed or desired for a ticket to proceed, they receive the needs-unit-tests workflow keyword. You can submit tests for existing tickets directly on the WordPress core Trac. Bonus points for submitting a bug report with a test case included.
Write new tests to improve our code coverage. Many areas of WordPress do not have adequate test coverage. Pick a function, class, or component and write tests for it. You can submit these tests on the WordPress Trac.
Fix or improve our existing test cases. There are many opportunities for improvement in the existing tests. Some of them are ancient and others are slow or fragile. Some do not tests well in multisite or under certain conditions. Some individual tests try to test too much, and could be improved by using data providers, dependencies, and more narrow assertions.
Unit tests for JavaScript code are currently much more limited in WordPress Core in comparison to PHP unit tests. For more information on JS unit tests, see the Make/Core post or the QUnit section of this Handbook.