Skip to content

Instantly share code, notes, and snippets.

@armeo
Forked from xentek/wp-unit-tests.md
Created April 2, 2013 10:20
Show Gist options
  • Save armeo/5291266 to your computer and use it in GitHub Desktop.
Save armeo/5291266 to your computer and use it in GitHub Desktop.

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

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