Mocking WordPress Hooks
Ensuring actions and filters are registered
use MyPlugin\MyClass;
use WP_Mock\Tools\TestCase as TestCase;
final class MyClassTest extends TestCase
{
public function testHookExpectations() : void
{
$classInstance = new MyClass();
WP_Mock::expectActionAdded('save_post', [$classInstance, 'myActionCallback'], 10, 2);
WP_Mock::expectFilterAdded('the_content', [$classInstance, 'myFilterCallback']);
$classInstance->addHooks();
}
}Asserting that closures have been added as hook callbacks
Asserting that actions and filters are applied
Asserting that an object has been passed
Last updated