[EventDispatcher] Clear orphaned events on TraceableEventDispatcher::reset

This commit is contained in:
Albert Casdemont 2018-07-10 13:02:47 +02:00
parent a552e849d5
commit d3260dfdcd
2 changed files with 12 additions and 0 deletions

View File

@ -217,6 +217,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
public function reset()
{
$this->called = array();
$this->orphanedEvents = array();
}
/**

View File

@ -271,6 +271,17 @@ class TraceableEventDispatcherTest extends TestCase
$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