Skip to content

Commit

Permalink
bug #27913 [EventDispatcher] Clear orphaned events on reset (acasadem…
Browse files Browse the repository at this point in the history
…ont)

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 #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
  • Loading branch information
fabpot committed Jul 12, 2018
2 parents 4f1647e + d3260df commit 10f7dcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -217,6 +217,7 @@ public function getOrphanedEvents(): array
public function reset()
{
$this->called = array();
$this->orphanedEvents = array();
}

/**
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 10f7dcc

Please sign in to comment.