I wanted to start contributing to the WordPress unit tests so I needed to install PHPUnit. Turned out it was harder than it might seem (I had a tough time getting it all working) so I thought I’d blog what finally ended up working for me to help save some people some time.
Assuming you already have PHP and MySQL installed, here’s the steps you need to take:
- Install PEAR, a dependency for PHPUnit:
- Visit http://pear.php.net/go-pear.phar in your browser and save the file into your PHP directory. This is the folder where you can find
php.exe. - Open an administrator command prompt. On Vista or Windows 7, hit your Windows key, type “cmd”, right-click the resulting “cmd.exe” search result, and select “Run as administrator”. Navigate to the folder where you have PHP installed, the same folder where you saved the file in the previous step.
- Type the following command to execute the file you just downloaded:
php go-pear.phar - After a moment, you should start being prompted for some things. The installer is pretty self-explanatory and I think you want a system installation rather than a local one.
- Open the folder where PHP is installed and double-click the
PEAR_ENV.regfile that has been created. This allows you to run thepearcommand from any folder. - Verify PEAR is working by running the command
pear version
- Visit http://pear.php.net/go-pear.phar in your browser and save the file into your PHP directory. This is the folder where you can find
- Install PHPUnit:
- Turn on
auto_discoverin PEAR by typing the following command at the command line:pear config-set auto_discover 1 - Download and install PHPUnit by running the following command:
pear install pear.phpunit.de/PHPUnit - In order to be able to run the
phpunitcommand from any folder, you need to add it to your WindowsPathvalue. Right-click My Computer → Properties → Advanced system settings → Environmental Variables → select “Path” under “System Variables” → Edit → Add a semi-colon (;) and then the full path to your PHP folder onto the end of the value, for example like this:;D:\Webserver\php - Verify PHPUnit is working by running the command
phpunit --version
- Turn on
- Set up the WordPress unit tests by following the rest of the steps on the WordPress Core Contributor Handbook now that you have PHPUnit installed.
Done!