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