The CMB Test Suite uses PHPUnit to help us maintain the best possible code quality.
The master branch of CMB is automatically tested using GitHub Actions. The badge above will show you the latest test's output. GitHub Actions will also automatically test all new Pull Requests to make sure they will not break our build.
git clone git@github.com:CMB2/CMB2.git ./Use Composer to install PHPUnit and other dependencies:
composer installThis installs PHPUnit 9.6+ and the required polyfills for compatibility.
If you haven't already installed the WordPress testing library, we have a helpful script to do so for you.
Note: you'll need to already have svn, wget, and mysql available.
Change to the CMB directory:
cd CMB2# Standard MySQL setup
bash tests/bin/install-wp-tests.sh wordpress_test root '' localhost latest
# For Local by Flywheel (adjust path to your site's MySQL socket)
bash tests/bin/install-wp-tests.sh wordpress_test root root "/Users/USERNAME/Library/Application Support/Local/run/SITE_ID/mysql/mysqld.sock" latestParameters:
wordpress_testis the name of the test database (all data will be deleted!)rootis the MySQL user name''orrootis the MySQL user passwordlocalhostor socket path is the MySQL server hostlatestis the WordPress version; could also be6.4,6.3etc.
Note: MySQL must be running in order for tests to run.
composer test
# or directly
vendor/bin/phpunitYou can set up a git pre-commit hook to run PHPUnit before each commit:
echo '#!/bin/sh
vendor/bin/phpunit' > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitIf a test fails, the commit will be rejected, giving you the opportunity to fix the problem first.