8000 Pass in Closure for Hooks · Issue #235 · 10up/wp_mock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Pass in Closure for Hooks #235
Open
Open
@badasswp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0