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 · 2 comments · May be fixed by #254
Open

Support for Types Inclusion in expectFilter #253

badasswp opened this issue Jan 25, 2025 · 2 comments · May be fixed by #254

Comments

@badasswp
Copy link

badasswp commented Jan 25, 2025

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( 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 ) );
@nmolham-godaddy
Copy link
Contributor

The base idea is pretty sound 💯

Do you have a proposal PR that we can look at?

@badasswp
Copy link
Author

badasswp commented Feb 1, 2025

Hi @nmolham-godaddy Thanks for the feedback. Please see this PR which resolves this issue.

@badasswp badasswp linked a pull request Feb 2, 2025 that will close this issue
8 tasks
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

Successfully merging a pull request may close this issue.

2 participants