From d3260dfdcd2cb365788ea3bc41e91739a8acb81d Mon Sep 17 00:00:00 2001 From: Albert Casdemont Date: Tue, 10 Jul 2018 13:02:47 +0200 Subject: [PATCH] [EventDispatcher] Clear orphaned events on TraceableEventDispatcher::reset --- .../Debug/TraceableEventDispatcher.php | 1 + .../Tests/Debug/TraceableEventDispatcherTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php index 3b6e7cc39314..8d851623fb67 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php @@ -217,6 +217,7 @@ public function getOrphanedEvents(): array public function reset() { $this->called = array(); + $this->orphanedEvents = array(); } /** diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php index 2521f741ea1f..ab3b33e3779a 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php @@ -271,6 +271,17 @@ public function testListenerCanRemoveItselfWhenExecuted() $this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed'); } + + public function testClearOrphanedEvents() + { + $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); + $tdispatcher->dispatch('foo'); + $events = $tdispatcher->getOrphanedEvents(); + $this->assertCount(1, $events); + $tdispatcher->reset(); + $events = $tdispatcher->getOrphanedEvents(); + $this->assertCount(0, $events); + } } class EventSubscriber implements EventSubscriberInterface