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 WP_UnitTestCase - add dont_restore_hooks() method #44

Open
bobbingwide opened this issue Sep 3, 2023 · 1 comment
Open

Update WP_UnitTestCase - add dont_restore_hooks() method #44

bobbingwide opened this issue Sep 3, 2023 · 1 comment
Assignees

Comments

@bobbingwide
Copy link
Owner

While attempting to develop in situ PHPUnit tests for the acf-fields-block plugin I had problems due to the default WordPress unit test case class restoring hooks that had been attached by dependent plugins. In this case it was Advanced Custom Fields PRO.

See bobbingwide/field-block-for-acf-pro#15 (comment)

My workaround was to comment out the call to _restore_hooks() in the tearDown() method.
I then decided to allow the plugin's PHPUnit tests to decide whether or not to restore hooks.
The solution is to add a new method dont_restore_hooks() which will set $this->restore_hooks to false
and to change tearDown()to call maybe_restore_hooks() instead of _restore_hooks().

The calling test class overrides the tearDown() method as follows.

function tearDown() : void {
		$this->dont_restore_hooks();
		parent::tearDown();
	}
@bobbingwide bobbingwide self-assigned this Sep 3, 2023
@bobbingwide
Copy link
Owner Author

Additional requirement

The PHPUnit Tests for oik-batch need to be updated so that they pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant