From f4e87f5303053984b2b7499beac95bc835481a35 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 25 Jul 2012 11:17:52 +0000 Subject: [PATCH] Pass arguments to EventDispatcher::triggerEvent by reference --- .../webim/libs/classes/EventDispatcherTest.php | 13 +++++-------- .../plugin.mibew.inc.php | 4 ++-- .../webim/libs/classes/event_dispatcher.php | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/messenger/tests/webim/libs/classes/EventDispatcherTest.php b/src/messenger/tests/webim/libs/classes/EventDispatcherTest.php index cb66c78a..9a144601 100644 --- a/src/messenger/tests/webim/libs/classes/EventDispatcherTest.php +++ b/src/messenger/tests/webim/libs/classes/EventDispatcherTest.php @@ -139,17 +139,14 @@ class EventDispatcherTest extends PHPUnit_Framework_TestCase { // Following code wait for trigger user error, which converts by PHPUnit to an // Exception try{ - $dispatcher->triggerEvent('unregistered_event', array()); + $dispatcher->triggerEvent('unregistered_event'); $this->fail("Error expected!"); } catch(Exception $e) {} - // Try to thrigger registered event - // Wait for exception thrown by - // Phpunit_autotest_plugin_managerPlugin::testEventListener() - try{ - $dispatcher->triggerEvent('some_another_test_event', array()); - $this->fail("Exception excpected!"); - } catch(Exception $e) {} + // Try to trigger registered event + $test_array = array(); + $dispatcher->triggerEvent('some_another_test_event', $test_array); + $this->assertEquals('some_test_value', $test_array['test']); } } diff --git a/src/messenger/tests/webim/libs/classes/phpunit_autotest_plugin_manager/plugin.mibew.inc.php b/src/messenger/tests/webim/libs/classes/phpunit_autotest_plugin_manager/plugin.mibew.inc.php index dc6e052c..5dea2646 100644 --- a/src/messenger/tests/webim/libs/classes/phpunit_autotest_plugin_manager/plugin.mibew.inc.php +++ b/src/messenger/tests/webim/libs/classes/phpunit_autotest_plugin_manager/plugin.mibew.inc.php @@ -28,8 +28,8 @@ Class Phpunit_autotest_plugin_managerPlugin extends Plugin{ } } - public function testEventListener($vars) { - throw new Exception(); + public function testEventListener(&$vars) { + $vars['test'] = 'some_test_value'; } public function __construct(){ diff --git a/src/messenger/webim/libs/classes/event_dispatcher.php b/src/messenger/webim/libs/classes/event_dispatcher.php index 324f23bf..2af30e0b 100644 --- a/src/messenger/webim/libs/classes/event_dispatcher.php +++ b/src/messenger/webim/libs/classes/event_dispatcher.php @@ -139,10 +139,10 @@ Class EventDispatcher { * Triggers the event * * @param string $event_name Event's name - * @param array $arguments Arguments passed to listener + * @param array &$arguments Arguments passed to listener * @return boolean true on success or false on failure */ - public function triggerEvent($event_name, $arguments = array()){ + public function triggerEvent($event_name, &$arguments = array()){ // Check event exists if (! array_key_exists($event_name, $this->events)) { trigger_error("Event '{$event_name}' does not exists!", E_USER_WARNING);