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.
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();
}
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 https://github.com/bobbingwide/acf-field-block/issues/15#issuecomment-1703859969
My workaround was to comment out the call to
_restore_hooks()
in thetearDown()
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 methoddont_restore_hooks()
which will set$this->restore_hooks
to false and to changetearDown()
to callmaybe_restore_hooks()
instead of_restore_hooks()
.The calling test class overrides the
tearDown()
method as follows.