WP_Mock or Brain Monkey? Which is the better Mocking Library for WordPress?

Travis Weston
Dev Genius
Published in
5 min readJan 20, 2021

Photo by James Lee on Unsplash

Let’s get this out of the way upfront: I’ll be using Brain Monkey moving forward. If you’re interested in knowing why, keep reading.

What is a Mocking Library?

If you have no idea what a mocking library is, you likely aren’t doing enough testing. Without going into too much detail here, the specific use case that I am looking to solve here is creating a testing suite for WordPress plugins that does not require spinning up the entire WordPress application.

Both of these libraries allow you to “mock” WordPress functionality, which allows you to test your own code in a contained environment. So instead of relying on running your code through the entire WordPress core, you test your code in isolation, and you are positive that if there is anything wrong your code is not to blame.

So, how do you decide between the two?

I’m lucky in that I came to this question at the very start of a new project. Because of that, my decision process was simple: I installed both, and started making tests with both.

Note: If you do this, make sure you group those tests that you create with WP_Mock and those tests that you create with Brain Monkey. That’s because methods mocked with WP_Mock cannot be re-mocked by Brain Monkey, and vice versa.

Reputation

The very first thing I look at when choosing a framework like this is reputation. In that regard, WP_Mock is the clear winner. They have a great reputation, and are backed by an experienced group of developers that are trusted in the community — 10up.

Brain Monkey is newer, but has some great reviews. It is maintained by Giuseppe Mazzapica, which is another hit, since a sole maintainer can hinder development at times.

Focus/Usage

WP Mock is limited here. It is strictly a mocking library for PHPUnit and WordPress. If I were to use it, I would only be able to use it for WordPress projects, and only if I continue to use PHPUnit as my testing framework.

This isn’t that big a deal, as I will likely continue to do both of those things. That said…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Travis Weston is a Software Developer focused on PHP, DevEx, and DevEd. Connect with him on Twitter @n00bJackleCity