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

Skip to content

Commit d3260df

Browse files
committed
[EventDispatcher] Clear orphaned events on TraceableEventDispatcher::reset
1 parent a552e84 commit d3260df

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)