Skip to content

Instantly share code, notes, and snippets.

@markjaquith
Last active March 13, 2017 20:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markjaquith/2312948 to your computer and use it in GitHub Desktop.
Save markjaquith/2312948 to your computer and use it in GitHub Desktop.
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 pear.phpunit.de/PHPUnit
  7. Make an SVN checkout of http://develop.svn.wordpress.org/
  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!

Troubleshooting

  • 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.
@emersonthis
Copy link

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