diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index c0f839b9db905..fbf69ffe31dec 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -94,7 +94,7 @@ public function getListeners(string $eventName = null) public function getListenerPriority(string $eventName, $listener) { if (empty($this->listeners[$eventName])) { - return null; + return 0; } if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure && 2 >= \count($listener)) { @@ -114,7 +114,7 @@ public function getListenerPriority(string $eventName, $listener) } } - return null; + return 0; } /** diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php b/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php index 88c707c9a360b..8f25e162e06f6 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php @@ -62,7 +62,7 @@ public function getListeners(string $eventName = null); * * @param callable $listener The listener * - * @return int|null The event listener priority + * @return int The event listener priority, defaults to 0 */ public function getListenerPriority(string $eventName, $listener); diff --git a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php index ea9fe8c1b6cdc..5d3e4caf1cb09 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php @@ -123,8 +123,8 @@ public function testGetListenerPriority() $this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1)); $this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2)); - $this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2)); - $this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {})); + $this->assertEquals($this->dispatcher->getListenerPriority('pre.bar', $listener2), 0); + $this->assertEquals($this->dispatcher->getListenerPriority('pre.foo', function () {}), 0); } public function testDispatch()