Skip to content

Pass in Closure for Hooks #235

Description

@badasswp

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
        }
    ]
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions