6 * Interface HookInterface
9 * This interface allows you to subscribe to hooks as part of the test.
10 * Simply create an eponymous hook function (e.g. `hook_civicrm_post()`).
13 * class MyTest extends \PHPUnit_Framework_TestCase implements \Civi\Test\HookInterface {
14 * public function hook_civicrm_post($op, $objectName, $objectId, &$objectRef) {
15 * echo "Running hook_civicrm_post\n";
20 * Similarly, to subscribe using Symfony-style listeners, create function with the 'on_' prefix:
23 * class MyTest extends \PHPUnit_Framework_TestCase implements \Civi\Test\HookInterface {
24 * public function on_civi_api_authorize(AuthorizeEvent $e): void {
25 * echo "Running civi.api.authorize\n";
27 * public function on_hook_civicrm_post(GenericHookEvent $e): void {
28 * echo "Running hook_civicrm_post\n";
33 * At time of writing, there are a few limitations in how HookInterface is handled
34 * by CiviTestListener:
36 * - The test must execute in-process (aka HeadlessInterface; aka CIVICRM_UF==UnitTests).
37 * End-to-end tests (multi-process tests) are not supported.
38 * - Early bootstrap hooks (e.g. hook_civicrm_config) are not supported.
39 * - This does not support priorities or registering multiple listeners.
41 * If you need more advanced registration abilities, consider using `Civi::dispatcher()`
42 * or `EventDispatcherInterface`.
44 * @see CiviTestListener
46 interface HookInterface
{