A recent project has me working quite a bit with WordPress and WP Plugin development. After getting my sea legs on the subject of Plugin Development, I started going down the path to writing tests for the plugin I am developing.
$this->assertEquals( ‘testing_framework’, ‘PHPUnit’);
PHPUnit is the testing framework used on WordPress Core, so I decided to use the same framework while writing my tests. It has been a bit of a learning curve for me to get started with testing a Plugin, so this is the first in a series of posts I will be writing about getting a testing environment setup on OS X Mavericks.
For the record, my local setup is a Macbook Pro that is running OS X 10.9.2, and the Apache/PHP/MySql services are being handled by MAMP. MAMP is pretty straightforward to get running so I’ll move ahead to the subject of this post – WP-CLI.
The WP Toolbelt
My first exposure to WP_CLI came when I was looking for a less painful way to perform upgrades on The Longboard Blog. For anyone at home on the command line WP_CLI just feels right. For example, when our marketing person wants some hot new plugin installed, I just fire up an ssh session and jam in `wp plugin install omg-internet-cats` to install her desired plugin.
But on my quest to TDD WordPress Plugin nirvana lead me right back to WP_CLI. You see to get the test suite setup and running easily, WP_CLI is a key ingredient.
First things first, grab some handy info to complete the install. First of which is firing up MAMP’s start page (likely here if MAMP is running: http://localhost:8888/MAMP/?language=English) and grab your PHP path from the phpinfo tab. It will likely be /Applications/MAMP/bin/php/php5.5.3, with the last directory varying depending on your PHP version.
Next the install is super quick and easy, just
cd to your MAMP php directory and do the following:
curl -L https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar
Verify it works:
php wp-cli.phar --info
And create a shortcut:
chmod +x wp-cli.phar
mv wp-cli.phar /usr/bin/wp
Then the only unique part of the install is to add in some convenience aliases to your ~/.bash_profile. From the command line again run:
And append the following to the end of your profile, be sure to adjust the path to your MAMP path you looked up in step #1:
Now if you open up a new terminal window, or
source ~/.bash_profile you can start
wp‘in like a champ. Stay tuned for the next post in the series about setting up the PHPUnit test stack in your project.