Open
Description
Feature request
At the moment we can currently pass a Closure as the return value when mocking functions using the \WP_Mock::userFunction
like so:
WP_Mock::userFunction(
'get_post_meta',
[
'times' => 3,
'return' => function( $post_id, $key, $single ) {
if ( $key === 'some_meta_key' ) {
return 'some value';
}
return 'another value';
}
]
);
This really comes in handy when we are in a loop situation and we need to do this several times.
Proposed solution
Can this same approach be employed for hooks? It would be very handy to do this in one swoop, just like its userFunction counterpart.
WP_Mock::expectFilter(
'custom_post_types',
[
'times' => 3,
'return' => function( $post_type ) {
return $post_type
}
]
)