PHPUnit tests and WP-CLI

I recently discovered an easy way to add unit tests to my plugins. I’ve been using WP-CLI for years now to set up new local installs of WordPress and found out it has a command specifically for setting up PHPUnit for plugins. This post is partially for my future self so I can remember how to do all this. FYI, I’m on a Mac, so all the commands will be OS X-specific.

Install and Configure PHPUnit

Start by installing PHPUnit using Homebrew:

brew install phpunit

That installs the latest version of PHPUnit and makes it ready to use with the global keyword “phpunit”.

Next, use WP-CLI to setup the test suites and such needed for PHPUnit. I recommend running this command from the plugin’s directory.

wp scaffold plugin-tests my-plugin

Replace the “my-plugin” part with your plugin name.

If you aren’t already in your plugin directory, change to that now. Then you’ll run the installation bash script.

bin/ wordpress_test root '' localhost latest

Notes about this command:

  • ‘wordpress_test’ is the MySQL database created by this script and used for testing
  • ‘root’ is your local MySQL user
  • ” is where your local MySQL user password goes
  • ‘localhost’ is where you MySQL server is located
  • ‘latest’ changes the version of WordPress to use for testing.

Once you’ve run this script, you’re ready to start writing tests and running them using the ‘phpunit’ command. Here’s the rub though: the script installs WordPress and the testing suite in the /tmp directory. Why is that a  problem? On my computer, at least, the /tmp directory removes anything installed there upon reboot. Which means I need to re-run the tests bash script every time I reboot the computer.

Since we developers prefer not repeating ourselves, here’s how to configure things for a more permanent solution.


What I’m advising here is to move the stuff installed in /tmp to somewhere else, then fix all the references so they still work. So, run all of the above, then navigate to your /tmp folder. Move the /wordpress and /wordpress-tests-lib folders to another location outside the /tmp folder. I moved mine into a directory called unittests in my Dropbox folder.

Go to your Home folder and either open or create the .bash_profile file. You’ll probably need to tell Finder to show Hidden files first. In your .bash_profile file, add the following line, using your new directory location:

export WP_TESTS_DIR="/Your/New/Folder/Location/unittests/wordpress-tests-lib"

This line tells the PHPUnit bootstrap.php file where to find the test WordPress install and test suite files.

Now, go to the wordpress-tests-lib directory and open the wp-tests-config.php file. Edit the ABSPATH constant to the ‘/wordpress’ directory you copied over from /tmp earlier. Something like:

define( 'ABSPATH', '/Your/New/Folder/Location/unittests/wordpress//' );

Save the file and reboot your computer. Now, the tests setup by WP-CLI know where the testing WordPress is located, it doesn’t disappear when you install updates or reboot, and you can create and run PHPUnit tests for your plugins!

ArtistDataPress Expiration

In case you haven’t heard, ArtistData is shutting down. Since AritstDataPress merely re-displays the feed from ArtistData, the plugin will also be shutting down. The final date is October 14.

I recommend checking out either BandsInTown or GigPress. BandsInTown covers the online service bit; GigPress keeps everything on your site. I’ve seen good results from both, so you can’t lose.

ArtistDataPress updated to v0.72!

Its been a long year. I’ve been trying to get back to ArtistDataPress and finally had a break in the schedule. So I resolved the larger issues people have brought up on the WordPress support forums. First off, if anyone feels I abandoned the plugin, please forgive me. Paid gigs come before free plugins. However, my schedule has freed up quite a bit now, so I should be able to make regular updates.

Version 0.72 brings the following changes:

  • BUG FIX: Resolved the “undefined function get_example_data()” error
  • BUG FIX: Removed the transient caching – causing too many errors and complaints
  • Removed “Custom” template option; added custom template explanation instead.
  • Changed Twitter account info
  • Added plugin icon to assets

ArtistDataPress is also compatible with the current version of WordPress, so there’s also that. Happy updating!

BP Profile Widgets 0.5 is out!

This is a major update for BP Profile Widgets. One thing everyone asked for is multiple instances. Since this plugin creates a BuddyPress profile field (or two) for each widget, it was a bit challenging to figure this one out. But, I did and you now have up to 5 instances of each widget available!

The other big request was to fix the crazy bug I introduced in version 0.4. Wait, software with bugs? What? Yep. I tried out a new way of getting data from the URLs people put on their profiles, but apparently the new method only works on certain server configurations. Still not sure why, but I’ve opted to simply remove it. I could already use the older way just fine, so I’ll stop trying to fix what ain’t broke!

I’ve also had several requests to internationalize BP Profile Widgets, so I read up on what needed to be done and did it. If you want to interpret this plugin into your language, check out the answer on this page and send me your translation files. I’ll update the plugin with new translations as they come in.

Lastly, I did add a few video services to the video player plugin: Wistia,, and Vine!

BP Profile Widgets

I’m excited to announce I’ve finally updated my BuddyPress plugins! I combined them all into one plugin called BP Profile Widgets. This version has many awesome upgrades like being able to select which widgets are available to use through the plugin options. When you select a widget, the plugin automatically creates the appropriate Profile Field Group and Profile Fields – no more naming issues!

On top that, I also updated the widgets with better versions of the players, oEmbed support when possible, and more vendors included. I hope you enjoy the new plugin!

ArtistDataPress version 0.6 released!

I’ve added some really cool stuff in this release and I’m proud to announce its officially out!

First off, I’ve added feed caching. Let me ‘splain. Before, ADP would go ask ArtistData’s servers for your info every time you reloaded the page. You may have noticed how slow that was. Fortunately, WordPress has a way that I could save the feed data when I fetch it from ArtistData and it makes everything much, much faster! The one trade-off is you’ll need to wait about an hour for new events to show up on your site. If that needs to be changed, please let me know and I’ll alter the timing based on your feedback. But I figure an hour is short enough.

Second, all the layouts, including widgets, are now responsive, which means they look good on mobile and tablets, as well as your laptop. This is just the way things are going in the web development world and I’m still surprised I hadn’t already built this in before.

The rest of the changes are fairly minor. I altered the way some layouts were done in the CSS to name things more consistently, and make them easier to read. I also lightened up the code a bunch by getting rid of stuff I didn’t need.

Hope you all enjoy the update, let me know of any bugs and/or suggestions.

Introducing ArtistDataPress 0.5!

Its been a while since ADP was updated and I know lots of people haven’t cared for the previous update that, in some cases, took away their ability to view their plugin settings. That should be resolved with this 0.5 update.

Previously, ADP was using a PHP library called cURL to fetch the XML feed (the raw shows data) from ArtistData. Fortunately, there’s a nice built-in WordPress function called wp_remote_get that uses HTTP’s GET method to fetch an external URL. This means, your server settings really shouldn’t matter because every server supports HTTP. Hopefully, that’s the last we hear of issues getting the XML feed. 🙂

I also perused the support forums on and found several requests for features. I’ve added some great new features that have been highly requested:

You can now have multiple instances of ADP by using the [artistdatapress] shortcode to specify how many show you want to display and from which url. Use it like this:


[artistdatapress maxshows=20 feedurl=]


The values in the shortcode will override the plugin settings.

I also added the iCal layout for the widget and you choose that on the widget’s settings.

Overall, I streamlined the code and improved the logic and a bunch of other stuff under the hood that should make it easier to update later. Hope you enjoy!

BP Profile Video Widget for BuddyPress updated to 0.3

I released the 0.3 update for BP Profile Video Widget earlier today.  This update includes one big change: the elimination of the Service profile field.  The plugin will auto-detect the service being used based on the video’s URL.  I also included support for the new Youtube short URLs and embedding of Facebook videos.  I’d happily include other video services, but I’ll need some feedback as to which ones, so if you have uggestions, let me know in the comments!  Otherwise, happy updating!

ArtistDataPress Version 0.4 released!

Version 0.4 brings major changes to ArtistDataPress.  Most noticeably, you’ll see tabs on the options page now, with one dedicated to your choice for how your show listings appear on the page.

ArtistDataPress Layout Settings page
ArtistDataPress Layout Settings page


I’ve added a second layout option there and you should also notice the preview uses your actual data!  FYI, if your feed is empty or you don’t have a feed entered, I’ve got some example data in there to show you what it would look like with data.  Underneath, I’ve built a templating system, which will make it easier to add new layouts for both the page/post version and the widgets.  Version 0.4 includes two layouts for the page, Classic and iCal, and one for the widget, Classic.  I’ll be adding new layouts from now on, hopefully adding some cool options that will make displaying your show listings much more visually interesting.  Or at least different.

ArtistDataPress "Classic" Layout
ArtistDataPress “Classic” Layout
ArtistDataPress "iCal" Layout
ArtistDataPress “iCal” Layout

On a related note, if you’ve customized the CSS for your shows page, it will need to be updated.  I changed the CSS naming scheme for ADP to make it easier to add more layouts in the future.  The scheme for IDs and classes for all ADP properties is now: slushman_adp_(layout name)_(property name).  For example, the div containing the date and time on the Classic layout  for the Classic layout would be: slushman_adp_classic_date_time.  For the iCal layout, it would be: slushman_adp_ical_date_time.  Make sense?

I also fixed a bug relating to the Google micro-formatting I added a few updates ago.  Google can look at your page and, based on the formatting and meta data, can display your events in search results.  Part of that micro-formatting requires knowing the zip code where the event takes place.  Some artists use their “past” feed instead of the “future” feed, which causes an error with the zip code because ArtistData only started adding the zip code to shows in February of 2010.  Meaning any shows before then would throw an error.  Now, it simply comes back blank and no zip code is provided.  Which shouldn’t be a big deal since we’re talking about shows that have already happened. 🙂

So there you have it, ArtistDataPress 0.4.  Oh yeah, I also added some support links and a Paypal button on the General Settings page, in case you’re feeling generous.  It’s been a long two weeks and I know my wife will be happy to have me working on something else (or not working at all after hours).  Happy updating!

Announcing the ArtistDataPress plugin for WordPress

ArtistDataPress shows your shows calendar on your WordPress blog and automatically matches your theme!

If you’ve been using ArtistData and didn’t care for their iFrame calendar widget, I’ve got the solution for you: ArtistDataPress!  I wanted a way to display my band’s calendar on their site and on mine, but the AD iframe widget could only be styled once, which left my site with a calendar that didn’t match the rest of my theme.  ArtistDataPress takes the raw XML shows feed and makes it into an easy to style calendar for any page or post.  There’s even a sidebar widget!  You can choose what parts of the show information you want people to see through both the page and widget options.  You can download it from the WordPress Plugin Directory. You can read up on the plugin, it’s features, and get the FAQ on the plugin’s page.