Pass arguments to EventDispatcher::triggerEvent by reference

This commit is contained in:
Dmitriy Simushev 2012-07-25 11:17:52 +00:00
parent 17369b2f14
commit f4e87f5303
3 changed files with 9 additions and 12 deletions

View File

@ -139,17 +139,14 @@ class EventDispatcherTest extends PHPUnit_Framework_TestCase {
// Following code wait for trigger user error, which converts by PHPUnit to an // Following code wait for trigger user error, which converts by PHPUnit to an
// Exception // Exception
try{ try{
$dispatcher->triggerEvent('unregistered_event', array()); $dispatcher->triggerEvent('unregistered_event');
$this->fail("Error expected!"); $this->fail("Error expected!");
} catch(Exception $e) {} } catch(Exception $e) {}
// Try to thrigger registered event // Try to trigger registered event
// Wait for exception thrown by $test_array = array();
// Phpunit_autotest_plugin_managerPlugin::testEventListener() $dispatcher->triggerEvent('some_another_test_event', $test_array);
try{ $this->assertEquals('some_test_value', $test_array['test']);
$dispatcher->triggerEvent('some_another_test_event', array());
$this->fail("Exception excpected!");
} catch(Exception $e) {}
} }
} }

View File

@ -28,8 +28,8 @@ Class Phpunit_autotest_plugin_managerPlugin extends Plugin{
} }
} }
public function testEventListener($vars) { public function testEventListener(&$vars) {
throw new Exception(); $vars['test'] = 'some_test_value';
} }
public function __construct(){ public function __construct(){

View File

@ -139,10 +139,10 @@ Class EventDispatcher {
* Triggers the event * Triggers the event
* *
* @param string $event_name Event's name * @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 * @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 // Check event exists
if (! array_key_exists($event_name, $this->events)) { if (! array_key_exists($event_name, $this->events)) {
trigger_error("Event '{$event_name}' does not exists!", E_USER_WARNING); trigger_error("Event '{$event_name}' does not exists!", E_USER_WARNING);