Skip to content

Instantly share code, notes, and snippets.

@xentek
Created August 26, 2012 19:06
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xentek/3482677 to your computer and use it in GitHub Desktop.
WordPress Unit Tests Quick Start

WordPress Unit Tests Quick Start Guide

This quick start guide is geared towards installing PHPUnit on OSX in order to run the WordPress unit tests. It uses homebrew to install PHP using homebrew-php. You can likely skip this step if you've already got php and pear installed properly.

If you use MAMP, then try these instructions to use MAMP's php and pear to install PHPUnit.

install homebrew

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php

install php

brew install php54 --with-mysql --with-fpm --with-homebrew-openssl --with-imap --with-pgsql --with-intl
brew install php54-xdebug

install phpunit

sudo chmod u+w /usr/local/Cellar/php54/5.4.5/lib/php/.lock
sudo chmod g+w /usr/local/Cellar/php54/5.4.5/lib/php/.lock
pear update-channels
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit

Then add this to your $PATH: /usr/local/Cellar/php54/5.4.5/bin

checkout the test suite

svn co http://unit-test.svn.wordpress.org/trunk/ wp-unit-tests 
cd wp-unit-tests && svn up

create database

The test suite will destroy all data in the database, so create one dedicated to running the suite.

mysql -u root -p -e "DROP DATABASE wpunit; CREATE DATABASE wpunit; GRANT ALL PRIVILEGES ON wpunit.* TO wpunit@localhost IDENTIFIED BY 'wpunit'; FLUSH PRIVILEGES;"

configure test suite

cp wp-tests-config-sample.php wp-tests-config.php

Then edit wp-tests-config.php to connect to your database.

run the suite

phpunit

run a single test

phpunit tests/query.php

Further Reading

@al-the-x
Copy link

Instead of installing all those channel dependencies manually, try:

pear config-set auto_discover true

Then PEAR will automatically add the appropriate channels for dependencies. A big time-saver when the package maintainer is splitting packages across channels.

@xentek
Copy link
Author

xentek commented Aug 27, 2012

@al-the-x Did that, and it didn't work. Well, it worked in getting PHPUnit code on my system but until I forced it to discover the channels on ez.no and symfony, the phpunit cli runner wouldn't install for some reason. This may have just been me, but figured I'd prove the explicit instructions so that I might avoid requests for help ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment