## Mocking WP_CLI static methods in unit tests

Question

I’m writing unit tests (not integration) for a lib I’m working on. There, we created some WP-CLI commands that I’d like to test. Most of them are just renaming things, copying and pasting things over from the lib to the project.

And when something is successful or not a WP_CLI::success() or similar methods are used to output the message to the user (log, warning or error).

So what I’d like to do is just to output the contents of those methods so that I can test if the desired output happened.

Using Mockery I tried doing the following

// Mock certain WPCLI methods.
$wpCliMock = Mockery::mock('alias:WP_CLI');$wpCliMock

But it seems that it isn’t working because my tests throw Call to a member function fetchMock() on null and the error points to the success method.