Skip to content

Commit 27c122e

Browse files
committed
bug symfony#18388 [EventDispatcher] check for method to exist (xabbuh)
This PR was merged into the 2.8 branch. Discussion ---------- [EventDispatcher] check for method to exist | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#16301 (comment) | License | MIT | Doc PR | This change must be reverted after being merged into the `3.0` branch (the `getListenerPriority()` method was added to the interface in Symfony 3.0). Commits ------- 78ae2ad [EventDispatcher] check for method to exist
2 parents 2452e35 + 78ae2ad commit 27c122e

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)