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

Update Hook::safe_offset() to handle closures #183

Merged
merged 13 commits into from
Jan 3, 2023

Conversation

unfulvio-godaddy
Copy link
Member

@unfulvio-godaddy unfulvio-godaddy commented Dec 22, 2022

Summary

Reimplements #174 after implementing PhpStan and code styles in WP_Mock. Tests have been reworked in PhpUnit.

Quote from OP:

WP_Mock\Functions::type('callable') was causing a mismatch between the safe_offset values returned for the Mockery matcher and the actual closure being passed to add_action. The matcher was getting spl_object_hash'd, while the Closure was getting "__CLOSURE__". Now, safe_offset() treats Mockery matchers with type closure as "__CLOSURE__" too.

Closes: #89

Test

  • Unit tests pass

Open questions

I think we could rename safe_offset() into something more meaningful to make it easier to understand what it does. Seems this is used solely within the Hook abstract and Filter/Action implementations to get a string representations of the hook arguments. We could rename it using camel case and soft deprecate the former method.

As predicted, PhpStan will start spitting errors as tests, return types and such start to change. I covered some of the issues in this PR, but had to update the baseline to fix several unrelated positives which we can address in subsequent PRs.

@unfulvio-godaddy unfulvio-godaddy self-assigned this Dec 22, 2022
@coveralls
Copy link

coveralls commented Dec 22, 2022

Coverage Status

Coverage: 18.331% (+3.6%) from 14.743% when pulling 341b2a6 on feature/support-closures-anonymous-functions into 9d16132 on trunk.

@unfulvio-godaddy unfulvio-godaddy marked this pull request as ready for review December 22, 2022 04:58
@unfulvio-godaddy unfulvio-godaddy requested a review from a team December 22, 2022 04:58
@unfulvio-godaddy unfulvio-godaddy changed the title Update Hook::safe_offset() to handle closures (add tests) Update Hook::safe_offset() to handle closures Dec 22, 2022
@agibson-godaddy agibson-godaddy merged commit 4ea29a9 into trunk Jan 3, 2023
@agibson-godaddy agibson-godaddy deleted the feature/support-closures-anonymous-functions branch January 3, 2023 10:42
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 this pull request may close these issues.

WP_Mock::expectHookAdded() does not support calling add_action() with a closure
3 participants