Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Types Inclusion in expectFilter #253

Open
badasswp opened this issue Jan 25, 2025 · 0 comments
Open

Support for Types Inclusion in expectFilter #253

badasswp opened this issue Jan 25, 2025 · 0 comments

Comments

@badasswp
Copy link

Feature request

At the moment, the expectFilter expects a precise value to be passed as part of its argument. Can we also provide support for the use of types within our params like so:

\WP_Mock::expectFilter( 'my_filter', \WP_Mock\Functions::type( 'string' ) );

OR

\WP_Mock::expectFilter( 'my_filter', \WP_Mock\Functions::type( MyClass::class ) );

Proposed solution

I would like to see a situation where we are able to pass in types. This could cater for scenarios where we DO NOT have precise values, but we expect the instance of a Class to be passed in like so:

public function get_provider(): Provider {
    $tag_provider = get_option( 'tag_provider', [] )['name'] ?? '';

    switch ( $tag_provider ) {
	case 'WP_Tags':
	    $tag_provider = new TagProvider();
	    break;
    }

    /**
     * Filter Tag Provider.
     *
     * @param Provider $tag_provider Tag Provider.
     * @return Provider
     */
    return apply_filters( 'tag_provider', $tag_provider );
}

We should be able to do this within our test cases:

\WP_Mock::expectFilter( 'tag_provider', \WP_Mock\Functions::type( TagProvider::class ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant