The below is pretty much directly from the online manuals for PHPUnit and WordPress but copied here for my personal usage.
Install PHPUnit
- Download:
wget https://phar.phpunit.de/phpunit.phar - Make executable:
chmod +x phpunit.phar - Move globally:
sudo mv phpunit.phar /usr/local/bin/phpunit - Test
phpunit --version
Optionally, if you want to verify the signature, between steps #1 and #2:
- Download signature file
wget https://phar.phpunit.de/phpunit.phar.asc - Add the public key to our local file:
gpg --keyserver pgp.uni-mainz.de --recv-keys 0x4AA394086372C20A - Verify:
gpg phpunit.phar.asc
Install WordPress
- Get a local copy of WordPress
cd ~/
svn co http://develop.svn.wordpress.org/trunk/ wordpress-develop
cd wordpress-develop/
- Create a MySql database (replace
DATABASE_NAME_HERE,USERNAME_HEREandPASSWORD_HERE)
mysql -uroot -p -e "CREATE DATABASE DATABASE_NAME_HERE; GRANT ALL PRIVILEGES ON DATABASE_NAME_HERE.* TO USERNAME_HERE@localhost IDENTIFIED BY 'PASSWORD_HERE';FLUSH PRIVILEGES;" - Copy the test config file
cp wp-tests-config-sample.php wp-tests-config.php - Modify the variables
DB_NAME,DB_USERandDB_PASSWORDinwp-tests-config.phpREMEMBER!!!This database gets erased every time a unit test is run so DO NOT POINT IT AT A PRODUCTION DATABASE
vi wp-tests-config.php. - Sanity check by running the official test suite:
phpunit