8000 [EventDispatcher] fix BC layer by nicolas-grekas · Pull Request #31258 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[EventDispatcher] fix BC layer #31258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Member
Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #31221
License MIT
Doc PR -

@@ -242,7 +243,8 @@ protected function callListeners(iterable $listeners, string $eventName, $event)
if ($stoppable && $event->isPropagationStopped()) {
break;
}
$listener($event instanceof Event ? $event : new WrappedEvent($event), $eventName, $this);
// @deprecated: the ternary operator is part of a BC layer and should be removed in 5.0
$listener($event instanceof Event || !$listener instanceof WrappedListener ? $event : new WrappedEvent($event), $eventName, $this);
Copy link
Member
@chalasr chalasr Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$event instanceof Event is always false because of the early return l234
and !$listener instanceof WrappedListener is always true as listeners are optimized at this point (plain \Closure).
Broken test case:

diff --git a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php
index 8fd0305b0e..db3176dcd1 100644
--- a/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php
+++ b/src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php
@@ -18,6 +18,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Symfony\Component\Stopwatch\Stopwatch;
+use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
 
 class Trac
8000
eableEventDispatcherTest extends TestCase
 {
@@ -151,6 +152,15 @@ class TraceableEventDispatcherTest extends TestCase
         $this->assertArrayHasKey('stub', $listeners[0]);
     }
 
+    public function testDispatchContractsEvent()
+    {
+        $tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
+        $tdispatcher->addListener('foo', function () {}, 5);
+        $tdispatcher->dispatch(new ContractsEvent(), 'foo');
+        $listeners = $tdispatcher->getCalledListeners();
+        $this->assertArrayHasKey('stub', $listeners[0]);
+    }
+
     public function testGetCalledListenersNested()
     {
         $tdispatcher = null;

@chalasr
Copy link
Member
chalasr commented Apr 26, 2019

#31254 has been updated and fixes the issue mentioned above (with tests)

@nicolas-grekas nicolas-grekas deleted the ed-fix branch April 27, 2019 09:20
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0