Skip to content

Commit 93100b6

Browse files
Fix the legacy dispatcher argument order
Signed-off-by: Christoph Wurst <[email protected]>
1 parent 26a20ed commit 93100b6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

lib/private/EventDispatcher/SymfonyAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function __construct(EventDispatcher $eventDispatcher, ILogger $logger) {
6868
*/
6969
public function dispatch($eventName, $event = null): object {
7070
// type hinting is not possible, due to usage of GenericEvent
71+
if ($event instanceof Event && $eventName === null) {
72+
$this->eventDispatcher->dispatchTyped($event);
73+
return $event;
74+
}
7175
if ($event instanceof Event) {
7276
$this->eventDispatcher->dispatch($eventName, $event);
7377
return $event;

tests/lib/EventDispatcher/SymfonyAdapterTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ public function testDispatchSymfonyGenericEvent(): void {
100100
self::assertEquals($result, $wrapped);
101101
}
102102

103+
public function testDispatchOldSymfonyEventWithFlippedArgumentOrder(): void {
104+
$this->markTestSkipped('todo');
105+
106+
$event = new SymfonyEvent();
107+
$eventName = 'symfony';
108+
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
109+
$this->eventDispatcher->expects(self::once())
110+
->method('getSymfonyDispatcher')
111+
->willReturn($symfonyDispatcher);
112+
$symfonyDispatcher->expects(self::once())
113+
->method('dispatch')
114+
->with(
115+
$eventName,
116+
$event
117+
);
118+
119+
$result = $this->adapter->dispatch($eventName, $event);
120+
121+
self::assertSame($result, $event);
122+
}
123+
103124
public function testDispatchOldSymfonyEvent(): void {
104125
$event = new SymfonyEvent();
105126
$eventName = 'symfony';
@@ -120,6 +141,24 @@ public function testDispatchOldSymfonyEvent(): void {
120141
self::assertSame($result, $event);
121142
}
122143

144+
public function testDispatchCustomGenericEventWithFlippedArgumentOrder(): void {
145+
$this->markTestSkipped('todo');
146+
147+
$event = new GenericEvent();
148+
$eventName = 'symfony';
149+
$this->eventDispatcher->expects(self::once())
150+
->method('dispatch')
151+
->with(
152+
$eventName,
153+
$event
154+
)
155+
->willReturnArgument(1);
156+
157+
$result = $this->adapter->dispatch($eventName, $event);
158+
159+
self::assertSame($result, $event);
160+
}
161+
123162
public function testDispatchCustomGenericEvent(): void {
124163
$event = new GenericEvent();
125164
$eventName = 'symfony';

0 commit comments

Comments
 (0)