bug #23024 [EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null) (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null)

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

e7c4149e78 [EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null)
This commit is contained in:
Fabien Potencier 2017-06-01 15:38:21 -07:00
commit 32f65347f2
2 changed files with 2 additions and 1 deletions

View File

@ -105,7 +105,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
public function hasListeners($eventName = null)
{
if (null === $eventName) {
return (bool) count($this->listenerIds) || (bool) count($this->listeners);
return $this->listenerIds || $this->listeners || parent::hasListeners();
}
if (isset($this->listenerIds[$eventName])) {

View File

@ -56,6 +56,7 @@ abstract class AbstractEventDispatcherTest extends TestCase
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
$this->assertTrue($this->dispatcher->hasListeners());
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));