Skip to content

Request: control Strict Mode per test #249

Description

@BrianHenryIE

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions