Brain-WP/BrainMonkey

Mocking static methods?

Closed this issue · 1 comments

I tried using

Functions\when('My_Plugin\Helpers\General_Helper::get_array_value')->justReturn('value');

For mocking static method in my unit test, but I get an error

Brain\Monkey\Name\Exception\InvalidName: ''My_Plugin\Helpers\General_Helper::get_array_value'' is not a valid function name.

Is there a way to mock static methods with Brain Monkey?

Ok I found out how I can do that. Not an elegant solution, but it works. I need to alias the helper class and then mock the static methods that will be used instead of the real ones.

http://docs.mockery.io/en/latest/reference/creating_test_doubles.html#creating-test-doubles-aliasing