Unsure how to test / mock WP_User
Closed this issue · 2 comments
I am developing a plugin, and part of the plugin functionality uses WP_User to interact with the WordPress Database. I want to mock that functionality, and the documentation seems to suggest that it is possible using stubs :
https://brain-wp.github.io/BrainMonkey/docs/functions-stubs.html
Functions\stubs([
'is_user_logged_in' => true,
'current_user_can' => true,
'wp_get_current_user' => function() {
return \Mockery::mock('\WP_User');
}
]);
this code - when inserted into my project throws the following error :
Error: Call to undefined function Brain\Monkey\Functions\stubs()
@computamike Which version of Brain Monkey are you using? Also, how are you setting your tests? Are you sure you followed all the steps described here: https://brain-wp.github.io/BrainMonkey/docs/wordpress-setup.html?
Don't worry bout it - I managed to mock it using
\Mockery::mock( 'alias:WP_User' )
I don't know why Brain\Monkey\Functions\stubs doesn't seem to work - but I managed to get around my issue.
thanks