Skip to content

Commit

Permalink
bug #29714 [Event Dispatcher] fixed 29703: TraceableEventDispatcher r…
Browse files Browse the repository at this point in the history
…eset() callStack to null (mlievertz)

This PR was merged into the 3.4 branch.

Discussion
----------

[Event Dispatcher] fixed 29703: TraceableEventDispatcher reset() callStack to null

[Event Dispatcher] fixed 29703: TraceableEventDispatcher reset now sets callStack to null with test to dispatch after reset.

| Q             | A
| ------------- | ---
| Branch?       | 3.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29703    <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A <!-- required for new features -->

[Event Dispatcher] fixed 29703: TraceableEventDispatcher reset now sets callStack to null with test to dispatch after reset. Basically #29411 introduced an issue where calling dispatch after a reset would throw an error because now reset set callStack to array but dispatch expected either SplObjectStorage or null. Now reset sets null. Also added a test to verify dispatch works following a call to reset.

Commits
-------

51bcdb8 [Event Dispatcher] fixed 29703: TraceableEventDispatcher reset now sets callStack to null with test to dispatch after reset.
  • Loading branch information
fabpot committed Dec 29, 2018
2 parents 042f604 + 51bcdb8 commit f82beb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -221,7 +221,7 @@ public function getNotCalledListeners()

public function reset()
{
$this->callStack = array();
$this->callStack = null;
}

/**
Expand Down
Expand Up @@ -139,6 +139,18 @@ public function testClearCalledListeners()
$this->assertEquals(array(array('event' => 'foo', 'pretty' => 'closure', 'priority' => 5)), $listeners);
}

public function testDispatchAfterReset()
{
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$tdispatcher->addListener('foo', function () {}, 5);

$tdispatcher->reset();
$tdispatcher->dispatch('foo');

$listeners = $tdispatcher->getCalledListeners();
$this->assertArrayHasKey('stub', $listeners[0]);
}

public function testGetCalledListenersNested()
{
$tdispatcher = null;
Expand Down

0 comments on commit f82beb5

Please sign in to comment.