8000 [EventDispatcher] check for method to exist · symfony/symfony@78ae2ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 78ae2ad

Browse files
committed
[EventDispatcher] check for method to exist
1 parent e4816de commit 78ae2ad

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-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+
return 0;
109+
}
110+
107111
return $this->dispatcher->getListenerPriority($eventName, $listener);
108112
}
109113

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

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

76+
public function testGetListenerPriorityReturnsZeroWhenWrappedMethodDoesNotExist()
77+
{
78+
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
79+
$traceableEventDispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
80+
$traceableEventDispatcher->addListener('foo', function () {}, 123);
81+
$listeners = $traceableEventDispatcher->getListeners('foo');
82+
83+
$this->assertSame(0, $traceableEventDispatcher->getListenerPriority('foo', $listeners[0]));
84+
}
85+
7686
public function testAddRemoveSubscriber()
7787
{
7888
$dispatcher = new EventDispatcher();

0 commit comments

Comments
 (0)
0