Skip to content

Add ::setStrictModeForTest() function#265

Open
BrianHenryIE wants to merge 6 commits into10up:trunkfrom
BrianHenryIE:strict-mode
Open

Add ::setStrictModeForTest() function#265
BrianHenryIE wants to merge 6 commits into10up:trunkfrom
BrianHenryIE:strict-mode

Conversation

@BrianHenryIE
Copy link
Contributor

Summary

Adds WP_Mock::setStrictModeForTest() to control strict mode for an individual test, respecting the bootstrapped configuration for other tests.

Closes:

#249

Details

Adds setStrictModeForTest($enabled = true). This runs a backtrace to determine the currently running test, records the test name and preference as an associative array in WP_Mock::$__strict_mode_for_individual_test, then WP_Mock::strictMode() has been updated to check a new function ::isStrictModeForTest() which again determines the running test and if it has been set, uses the set value in preference to the default (bootstrapped) value.

NB: If tests are written using @test annotations or #[Test] attribute, they will not be recognised as tests.

An easier possibility would be to use WP_Mock\Tools\TestCase and use its set-up/tear-down methods, but that's not how I generally use this tool myself.

Once I get feedback and think a bit more about this, I'll add the appropriate documentation.

Contributor checklist

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly
  • I have added tests to cover changes introduced by this pull request
  • All new and existing tests pass

Testing

Tests added, phpcs passing, phpstan passing.

Reviewer checklist

  • Code changes review
  • Documentation changes review
  • Unit tests pass
  • Static analysis passes

@coveralls
Copy link

coveralls commented Jan 16, 2026

Coverage Status

coverage: 66.667% (+0.5%) from 66.142%
when pulling 03ed773 on BrianHenryIE:strict-mode
into 446ea70 on 10up:trunk.

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.

2 participants