Merge pull request #20944 from eileenmcnaughton/tiles
[civicrm-core.git] / Civi / Test / HookInterface.php
1 <?php
2
3 namespace Civi\Test;
4
5 /**
6 * Interface HookInterface
7 * @package Civi\Test
8 *
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()`).
11 *
12 * ```
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";
16 * }
17 * }
18 * ```
19 *
20 * Similarly, to subscribe using Symfony-style listeners, create function with the 'on_' prefix:
21 *
22 * ```
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";
26 * }
27 * public function on_hook_civicrm_post(GenericHookEvent $e): void {
28 * echo "Running hook_civicrm_post\n";
29 * }
30 * }
31 * ```
32 *
33 * At time of writing, there are a few limitations in how HookInterface is handled
34 * by CiviTestListener:
35 *
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.
40 *
41 * If you need more advanced registration abilities, consider using `Civi::dispatcher()`
42 * or `EventDispatcherInterface`.
43 *
44 * @see CiviTestListener
45 */
46 interface HookInterface {
47 }