quick WordPress plugin unit testing
If you want to "unit-test" your WordPress plugin, you don't have to set up all the WordPress plumbing like described at http://stackoverflow.com/q/9138215/571420
For most of the WP functions you can stub them with a simple return true.
function add_filter( $hook_point, $hook_callback, $mode ) {
return true;
}
function add_action( $hook_point, $hook_callback ) {
return true;
}
function register_activation_hook( $file, $callback ) {
return true;
}
Or if you need to control the stub behavior, go ahead and abuse the global namespace
$feed = false;
function is_feed() {
global $feed;
if $( feed ) return true;
return false;
Now you can test your plugin's logic independent of all the WordPress hooks and calls.
Example: https://github.com/groovecoder/wp-promote-mdn/blob/master/tests/PromoteMDNTest.php
Written by luke crouch
Related protips
1 Response
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#