WP-CLI and PHPUnit are excellent tools to use when developing and testing WordPress plugins. Composer is a great tool as well. It seems most people use Composer on a per-project basis – installing the packages they need just for the project they are working on. You can also install “global” packages, like these system tools, that you can use across multiple projects.
Assuming you already have composer installed, here are the commands you need to run to install a few global composer packages for WordPress development.
composer global require "phpunit/phpunit=5.1.*" composer global require "wp-cli/wp-cli=0.21.*"
Add a few lines to your .bash_aliases ( or .bashrc ) file to set a couple environment variables that WP-CLI uses. If you don’t set these variables, then WP-CLI will attempt to use your /tmp directory which you might not have permission to access. I tend to put these files under my home directory. So just replace with your username.
Also, we’ll add the composer bin files to the PATH environment variable.
# Set WordPress environment variables export WP_TESTS_DIR=/home/tmp/wordpress-tests-lib/ export WP_CORE_DIR=/home/tmp/wordpress/ # Add composer to PATH export PATH=~/.composer/vendor/bin:$PATH
Update: At the time of this writing, December 2015, those are the current version numbers for the composer packages. If you happen to be reading this later, you may want / need to update those to the current versions.