Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 84d3f9c

Browse files
committed
[EventDispatcher] check for method to exist
1 parent e4816de commit 84d3f9c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function getListeners($eventName = null)
104104
*/
105105
public function getListenerPriority($eventName, $listener)
106106
{
107+
if (!method_exists($this->dispatcher, 'getListenerPriority')) {
108+
throw new \LogicException(sprintf('The wrapped event dispatcher\'s class ("%s") does not implement the getListenerPriority() method.', get_class($this->dispatcher)));
109+
}
110+
107111
return $this->dispatcher->getListenerPriority($eventName, $listener);
108112
}
109113

src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ public function testGetListenerPriority()
7373
$this->assertSame(123, $tdispatcher->getListenerPriority('foo', $listeners[0]));
7474
}
7575

76+
/**
77+
* @expectedException \LogicException
78+
*/
79+
public function testGetListenerPriorityThrowsExceptionWhenWrappedMethodDoesNotExist()
80+
{
81+
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
82+
$traceableEventDispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
83+
$traceableEventDispatcher->addListener('foo', function () {}, 123);
84+
$listeners = $traceableEventDispatcher->getListeners('foo');
85+
86+
$traceableEventDispatcher->getListenerPriority('foo', $listeners[0]);
87+
}
88+
7689
public function testAddRemoveSubscriber()
7790
{
7891
$dispatcher = new EventDispatcher();

0 commit comments

Comments
 (0)