Skip to content
Snippets Groups Projects
Unverified Commit 5eb36d70 authored by totten's avatar totten Committed by GitHub
Browse files

Merge pull request #17251 from totten/master-hooktest

E2E_Core_HookTest - Fix test failure due to leak
parents e26695ba d21ceb54
Branches
Tags
No related merge requests found
......@@ -19,18 +19,23 @@ class HookTest extends \CiviEndToEndTestCase {
*/
public function testSymfonyListener_names() {
$calls = 0;
\Civi::dispatcher()
->addListener('hook_civicrm_e2eHookExample', function ($e) use (&$calls) {
$calls++;
$e->a['foo'] = 'a.name';
$e->b->bar = 'b.name';
});
$a = [];
$b = new \stdClass();
$this->hookStub(['a', 'b'], $a, $b);
$this->assertEquals(1, $calls);
$this->assertEquals('a.name', $a['foo']);
$this->assertEquals('b.name', $b->bar);
$hookExample = function ($e) use (&$calls) {
$calls++;
$e->a['foo'] = 'a.name';
$e->b->bar = 'b.name';
};
\Civi::dispatcher()->addListener('hook_civicrm_e2eHookExample', $hookExample);
try {
$a = [];
$b = new \stdClass();
$this->hookStub(['a', 'b'], $a, $b);
$this->assertEquals(1, $calls);
$this->assertEquals('a.name', $a['foo']);
$this->assertEquals('b.name', $b->bar);
}
finally {
\Civi::dispatcher()->removeListener('hook_civicrm_e2eHookExample', $hookExample);
}
}
/**
......@@ -43,18 +48,23 @@ class HookTest extends \CiviEndToEndTestCase {
*/
public function testSymfonyListener_int() {
$calls = 0;
\Civi::dispatcher()
->addListener('hook_civicrm_e2eHookExample', function ($e) use (&$calls) {
$calls++;
$e->arg1['foo'] = 'a.num';
$e->arg2->bar = 'b.num';
});
$a = [];
$b = new \stdClass();
$this->hookStub(2, $a, $b);
$this->assertEquals(1, $calls);
$this->assertEquals('a.num', $a['foo']);
$this->assertEquals('b.num', $b->bar);
$hookExample = function ($e) use (&$calls) {
$calls++;
$e->arg1['foo'] = 'a.num';
$e->arg2->bar = 'b.num';
};
\Civi::dispatcher()->addListener('hook_civicrm_e2eHookExample', $hookExample);
try {
$a = [];
$b = new \stdClass();
$this->hookStub(2, $a, $b);
$this->assertEquals(1, $calls);
$this->assertEquals('a.num', $a['foo']);
$this->assertEquals('b.num', $b->bar);
}
finally {
\Civi::dispatcher()->removeListener('hook_civicrm_e2eHookExample', $hookExample);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment