[EventDispatcher] fixed bug in EventDispatcher::disconnect if the second argument is null or ommitted
This commit is contained in:
parent
c1e873d1b0
commit
d376596f7e
@ -51,6 +51,11 @@ class EventDispatcher
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === $listener) {
|
||||
unset($this->listeners[$name]);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->listeners[$name] as $priority => $callables) {
|
||||
foreach ($callables as $i => $callable) {
|
||||
if ($listener === $callable) {
|
||||
|
@ -30,6 +30,10 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('listenToBarBar'), $dispatcher->getListeners('barbar'), '->disconnect() disconnects a listener for an event name');
|
||||
|
||||
$this->assertFalse($dispatcher->disconnect('foobar', 'listen'), '->disconnect() returns false if the listener does not exist');
|
||||
|
||||
$dispatcher->disconnect('bar');
|
||||
$this->assertEquals(array(), $dispatcher->getListeners('bar'), '->disconnect() without a listener disconnects all listeners of for an event name');
|
||||
$this->assertEquals(array('listenToBarBar'), $dispatcher->getListeners('barbar'), '->disconnect() without a listener disconnects all listeners of for an event name');
|
||||
}
|
||||
|
||||
public function testGetHasListeners()
|
||||
|
Reference in New Issue
Block a user