Skip to content

Instantly share code, notes, and snippets.



Last active Mar 13, 2017
What would you like to do?
How to get PHP Unit working for WordPress Unit Tests using MAMP Pro

WordPress Unit Tests using MAMP Pro

Note: Work in progress document.

Note: Change the PHP version number as appropriate to your MAMP Pro install.

  1. Add the following you your PATH, making sure that it is first: /Applications/MAMP/bin/php/php5\.3\.6/bin:/Applications/MAMP/bin/apache2/bin:/Applications/MAMP/bin
  2. mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bak
  3. source ~/.profile (or where ever you made your PATH changes)
  4. sudo pear update-channels && sudo pear upgrade pear
  5. sudo pear config-set auto_discover 1
  6. sudo pear install
  7. Make an SVN checkout of
  8. Copy wp-tests-config-sample.php to wp-tests-config.php
  9. Edit wp-tests-config.php and give it a fresh database. Repeat, a database with nothing else in it. The unit tests will drop every table in the database, so don't be stupid and give it access to a database that has anything else in it.
  10. (OPTIONAL) Increase the memory limit in wp-config.php: ini_set( 'memory_limit', '256M' );
  11. Add this to your ~/.profile (or equivalent): export WP_TESTS_DIR=~/svn/wp-dev/trunk/tests/phpunit/ (adjust path as appropriate).

You're set!


  • Run which phpunit — if the answer is /usr/bin/phpunit or similar, then you messed up the PATH. Make sure that the MAMP paths are first. You should get an answer like: /Applications/MAMP/bin/php/php5.3.6/bin/phpunit.

This comment has been minimized.

Copy link

@emersonthis emersonthis commented Aug 21, 2015

pear installation for PHPUnit no longer works.

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