Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xeiter/23d32dc36650685b3b1d85e29d0fb6e8 to your computer and use it in GitHub Desktop.
Save xeiter/23d32dc36650685b3b1d85e29d0fb6e8 to your computer and use it in GitHub Desktop.
[WordPress] Unit Testing with Pressmatic

Unit Testing with Pressmatic

  • Updated 20 August 2016

Installing Composer on Pressmatic

  1. SSH into the Pressmatic box
  2. $ apt-get update
  3. $ apt-get install curl php5-cli git subversion
  4. $ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Installing PHPUnit with Composer

  1. $ composer global require "phpunit/phpunit=4.8.*”
  2. $ export PATH="$PATH:$HOME/.composer/vendor/bin"

Setting Up Plugin Unit Tests

1. Generate the Plugin Test Files

$ wp scaffold plugin-tests <plugin-name>

2. Initialize the Environment Locally

$ cd $(wp plugin path <plugin-name> --dir) $ bash bin/install-wp-tests.sh wordpress_test root root localhost latest

3. Run the Plugin Tests

$ phpunit

TROUBLESHOOTING

1. Running phpunit errors out

Running phpunit could result in a fatal error stating that some core WordPress files in /tmp directory were not found.

It probably means that the bash bin/install-wp-tests.sh wordpress_test root root localhost latest command failed and you might have to delete the "wordpress-test" database as well as /tmp/wordpress and /tmp/wordpress-tests-lib directories and re-run the bash bin/install-wp-tests.sh wordpress_test root root localhost latest command again.

More Information

Read more informaton about this gist in this post.

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