blob: da28d24daa429b4bc0238cc6c7d7c1785d2d3b73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
class phpbb_event_dispatcher_test extends phpbb_test_case
{
public function test_trigger_event()
{
$dispatcher = new \phpbb\event\dispatcher(new phpbb_mock_container_builder());
$dispatcher->addListener('core.test_event', function (\phpbb\event\data $event) {
$event['foo'] = $event['foo'] . '2';
$event['bar'] = $event['bar'] . '2';
});
$foo = 'foo';
$bar = 'bar';
$vars = array('foo', 'bar');
$result = $dispatcher->trigger_event('core.test_event', compact($vars));
$this->assertSame(array('foo' => 'foo2', 'bar' => 'bar2'), $result);
// Test migrating events
$dispatcher->addListener('core.foo_br', function(\phpbb\event\data $event) {
$event['pi'] = '3.14159';
});
$dispatcher->addListener('core.foo_bar', function(\phpbb\event\data $event) {
$event['pi'] = '3.1';
});
$pi = '3';
$vars = array('pi');
$result = $dispatcher->trigger_event(['core.foo_bar', 'core.foo_br'], compact($vars));
$this->assertSame(array('pi' => '3.14159'), $result);
}
}
|