10 class HookTest
extends \CiviEndToEndTestCase
{
13 * This test ensures that CRM_Utils_Hook::invoke() dispatches via Symfony.
15 * This should be *in*addition* to dispatching through the UF event system,
16 * although the mechanics depend on the UF, so that part has to be tested per-UF.
18 * This uses the canonical form, `CRM_Utils_Hook::invoke(string[] $names...)`
20 public function testSymfonyListener_names() {
22 $hookExample = function ($e) use (&$calls) {
24 $e->a
['foo'] = 'a.name';
25 $e->b
->bar
= 'b.name';
27 \Civi
::dispatcher()->addListener('hook_civicrm_e2eHookExample', $hookExample);
31 $this->hookStub(['a', 'b'], $a, $b);
32 $this->assertEquals(1, $calls);
33 $this->assertEquals('a.name', $a['foo']);
34 $this->assertEquals('b.name', $b->bar
);
37 \Civi
::dispatcher()->removeListener('hook_civicrm_e2eHookExample', $hookExample);
47 private function hookStub($names, &$a, $b) {
48 return \CRM_Utils_Hook
::singleton()
49 ->invoke($names, $a, $b, \CRM_Utils_Hook
::$_nullObject, \CRM_Utils_Hook
::$_nullObject, \CRM_Utils_Hook
::$_nullObject, \CRM_Utils_Hook
::$_nullObject,
50 'civicrm_e2eHookExample');