Skip to content

Commit 10f7dcc

Browse files
committed
bug symfony#27913 [EventDispatcher] Clear orphaned events on reset (acasademont)
This PR was merged into the 4.1 branch. Discussion ---------- [EventDispatcher] Clear orphaned events on reset | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | NA | License | MIT | Doc PR | NA When the Orphaned Events feature was added in symfony#24392 it was forgotten to also clear them when the `reset` method on the `TraceableEventDispatcher` is called. This makes the Orphaned Events tab on the Event profiler an evergrowing list when using PHP-PM (or other event loop implementations). Commits ------- d3260df [EventDispatcher] Clear orphaned events on TraceableEventDispatcher::reset
2 parents 4f1647e + d3260df commit 10f7dcc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public function getOrphanedEvents(): array
217217
public function reset()
218218
{
219219
$this->called = array();
220+
$this->orphanedEvents = array();
220221
}
221222

222223
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ public function testListenerCanRemoveItselfWhenExecuted()
271271

272272
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
273273
}
274+
275+
public function testClearOrphanedEvents()
276+
{
277+
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
278+
$tdispatcher->dispatch('foo');
279+
$events = $tdispatcher->getOrphanedEvents();
280+
$this->assertCount(1, $events);
281+
$tdispatcher->reset();
282+
$events = $tdispatcher->getOrphanedEvents();
283+
$this->assertCount(0, $events);
284+
}
274285
}
275286

276287
class EventSubscriber implements EventSubscriberInterface

0 commit comments

Comments
 (0)