-
Notifications
You must be signed in to change notification settings - Fork 70
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
Request: control Strict Mode per test #249
Comments
Hi @BrianHenryIE thanks for looking into this and providing your thoughts about it. I am curious, why would you want to have hooks registered but not testing for it. Doesn't that repected an expected and desired behaviour? which means they should be tests for.
I see what you mean, but we have to consider other unknown use cases that whom ever using the package, would want to check/evaluate if strict mode is turned on or not depending of their test environment setup.
To better understand your point of view, can you open a simple PR to demonstrate that workflow change? Looking forward your feedback. |
Well, yesterday I was working with a specific method in a class and its hook is added in a "register hooks" type function that registers all the hooks for that class. It's legacy code. I do want to test the action that I'm working with; I do not want to imply the other hooks are correctly tested. Of course, I'd love if everything were thoroughly tested! I'll throw together a PR soon. |
Thanks @BrianHenryIE for the clarification, Looking forward to that PR |
Feature request
Currently, in my
bootstrap.php
I typically useWP_Mock::activateStrictMode()
.I would like to disable strict mode for some tests, in particular where I use
WP_Mock::expectActionAdded()
. Often, a function that adds one action adds many, but I will only be interested in testing that oneadd_action()
I've most recently added.With strict mode on, other
add_action
/add_filter
calls without their correspondingWP_Mock::expectActionAdded()
result in:Proposed solution
Add a public setter on
WP_Mock::$__strict_mode()
that can be used during individual tests, then inTestCase::setUp()
reset strict mode to the configured/default value.WP_Mock::activateStrictMode() only allows setting it before boostrap, and the documentation says it has to be enabled before bootstrap, but WP_Mock::strictMode() is only actually used in one, two places that don't read to me like it would matter.
The feature tests are already enabling/disabling it as desired in FeatureContext::forceStrictModeOn().
The text was updated successfully, but these errors were encountered: