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

Skip to content

Commit e9e4c79

Browse files
committed
bug #22541 [EventDispatcher] fix: unwrap listeners for correct info (dmaicher)
This PR was merged into the 2.8 branch. Discussion ---------- [EventDispatcher] fix: unwrap listeners for correct info | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | related to #22520 | License | MIT | Doc PR | - Fixes problem where listeners were displayed as `Symfony\Component\EventDispatcher\Debug\WrappedListener::__invoke() ` in the profiler. It now shows the correct callable. Commits ------- d8c5869 [EventDispatcher] fix: unwrap listeners for correct info
2 parents 1bee0ad + d8c5869 commit e9e4c79

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ private function getListenerInfo($listener, $eventName)
306306
'event' => $eventName,
307307
'priority' => $this->getListenerPriority($eventName, $listener),
308308
);
309+
310+
// unwrap for correct listener info
311+
if ($listener instanceof WrappedListener) {
312+
$listener = $listener->getWrappedListener();
313+
}
314+
309315
if ($listener instanceof \Closure) {
310316
$info += array(
311317
'type' => 'Closure',

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
16+
use Symfony\Component\EventDispatcher\Debug\WrappedListener;
1617
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1718
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1819
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -100,21 +101,41 @@ public function testAddRemoveSubscriber()
100101
$this->assertCount(0, $dispatcher->getListeners('foo'));
101102
}
102103

103-
public function testGetCalledListeners()
104+
/**
105+
* @dataProvider isWrappedDataProvider
106+
*
107+
* @param bool $isWrapped
108+
*/
109+
public function testGetCalledListeners($isWrapped)
104110
{
105111
$dispatcher = new EventDispatcher();
106-
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
107-
$tdispatcher->addListener('foo', $listener = function () {});
112+
$stopWatch = new Stopwatch();
113+
$tdispatcher = new TraceableEventDispatcher($dispatcher, $stopWatch);
114+
115+
$listener = function () {};
116+
if ($isWrapped) {
117+
$listener = new WrappedListener($listener, 'foo', $stopWatch, $dispatcher);
118+
}
119+
120+
$tdispatcher->addListener('foo', $listener, 5);
108121

109122
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
110-
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => 0)), $tdispatcher->getNotCalledListeners());
123+
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => 5)), $tdispatcher->getNotCalledListeners());
111124

112125
$tdispatcher->dispatch('foo');
113126

114-
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => null)), $tdispatcher->getCalledListeners());
127+
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'type' => 'Closure', 'pretty' => 'closure', 'priority' => 5)), $tdispatcher->getCalledListeners());
115128
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
116129
}
117130

131+
public function isWrappedDataProvider()
132+
{
133+
return array(
134+
array(false),
135+
array(true),
136+
);
137+
}
138+
118139
public function testGetCalledListenersNested()
119140
{
120141
$tdispatcher = null;

0 commit comments

Comments
 (0)