Request: control Strict Mode per test
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start in php/WP_Mock.php by reading activateStrictMode() and strictMode(), then inspect the strict-mode calls in WP_Mock/Hook.php and WP_Mock/Functions/Handler.php. Review TestCase::setUp() and FeatureContext::forceStrictModeOn() to understand reset behavior. Done means individual tests can control strict mode without leaking that state to other tests, with coverage for the requested behavior.
Written by the indexing model from the issue text.
Description
Feature request
Currently, in my bootstrap.php I typically use WP_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 one add_action() I've most recently added.
With strict mode on, other add_action/add_filter calls without their corresponding WP_Mock::expectActionAdded() result in:
Unexpected use of add_action for action init with callback BrianHenryIE\Example::init
Proposed solution
Add a public setter on WP_Mock::$__strict_mode() that can be used during individual tests, then in TestCase::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().
- Dominant language
- PHP
- Stars
- 714
- Forks
- 72
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 10up/wp_mock
-
`expectActionAdded( array( Functions::type( class-string ), 'method' ) )` fails when same method name used twicePossibly taken @faisalahammad claimed this 126 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 50/100
-
PHPCS reporting error on dependent library nikic/php-parser, hamcrest/hamcrest-phpPossibly taken @faisalahammad claimed this 126 days ago. OpenDependencies
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Pass in Closure for HooksPossibly taken @faisalahammad claimed this 126 days ago. OpenEnhancement Question
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Dependencies PHPUnit
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
10up/autoshare-for-twitter#438 ·
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
10up/Ad-Refresh-Control#240 ·
-
wpvc
Difficulty 1/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Backend bug severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
RunningJoke/allipunkte#74 ·