Unit Testing (or other testing methodologies) is one of those things that’s often relegated to larger software applications or enterprise-level projects and seems to be often overlooked in the context of WordPress.
Why is that?
WordPress is a web application and the tools, themes, plugins, and extensions that we build are software that run on top of said platform and the platform as well as the certain themes and/or plugins can be used anywhere from just a few hundred people up to several million people.
In some cases, I think this qualifies it as enterprise-grade. Regardless, WordPress should not be excluded from the best practices in software development. As such, I’m contributing a series of articles on Envato that is meant to help you get started with WordPress unit testing.
It’s targeted at beginners but aims to lay a foundation on which more experienced developers can build. Additionally, I’m providing working examples of plugins and themes both of which have been built using unit tests:
Throughout the series, I walk you through how to setup your local development environment to include both PHPUnit and the WordPress Testing framework along with giving a background of unit testing, what it is, why it matters, how it can improve plugin architecture and theme development.
All of the code is also available on my GitHub page:
- Hello Reader is a sample plugin
- Basic Theme is a sample theme
The article is a great walkthrough. Unfortunately I’m getting an error when I’m trying to update pear from the terminal. I tried the renaming note you suggested but still nothing. The error reads as follows:
Notice: unserialize(): Error at offset 276 of 1133 bytes in Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.
Thoughts?
Yep – locate the file: /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf and rename it to something such as pear.conf.old and you should be good to go.
$ mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.olg
Hey Tom,
Just wanted to thank you for writing this series on unit testing! It’s something that I’ve had on my TODO list to learn for a few months and I’ve only just been asked by a client to write some unit tests for a plugin we’re building.
Thanks to your series I’m up and running in under 20 mins. Great job Sir! :)
I was a little bit intimidated by unit testing at first but now I’m thinking I’ll work them into lots of our plugins for clients.
Sure thing, Bronson. Love hearing that – exactly how I hoped the post would help :).