bobbingwide / oik-batch

Batch interface to WordPress
https://www.oik-plugins.com/oik-plugins/oik-batch
GNU General Public License v2.0
0 stars 0 forks source link

Update WP_UnitTestCase - add dont_restore_hooks() method #44

Open bobbingwide opened 1 year ago

bobbingwide commented 1 year ago

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 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 commented 1 year ago

Additional requirement

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