Skip to content

Commit b3c3068

Browse files
Merge branch '4.3' into 4.4
* 4.3: Fix tests [Console] Fix commands description with numeric namespaces [HttpFoundation] Fixed typo [EventDispatcher] Better error reporting when arguments to dispatch() are swapped [Serializer] CsvEncoder::NO_HEADERS_KEY ignored when used in constructor [Form] Keep preferred_choices order for choice groups [Debug] work around failing chdir() on Darwin [PhpUnitBridge] Read configuration CLI directive [DI] Missing test on YamlFileLoader Revert "minor #34608 [Process] add tests for php executable finder if file does not exist (ahmedash95)" Simpler example for Apache basic auth workaround [Console] Fix trying to access array offset on value of type int [Config] Remove extra sprintf arg [VarDumper] notice on potential undefined index [HttpClient] turn exception into log when the request has no content-type [Process] add tests for php executable finder if file does not exist [Cache] Make sure we get the correct number of values from redis::mget() [TwigBridge] Add row_attr to all form themes [Serializer] Fix MetadataAwareNameConverter usage with string group
2 parents ab1c43e + 87a1ae7 commit b3c3068

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

EventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function dispatch($event/*, string $eventName = null*/)
5454

5555
if (\is_object($event)) {
5656
$eventName = $eventName ?? \get_class($event);
57-
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) {
57+
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof ContractsEvent || $eventName instanceof Event)) {
5858
@trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.', EventDispatcherInterface::class), E_USER_DEPRECATED);
5959
$swap = $event;
6060
$event = $eventName ?? new Event();

LegacyEventDispatcherProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function dispatch($event/*, string $eventName = null*/)
5959

6060
if (\is_object($event)) {
6161
$eventName = $eventName ?? \get_class($event);
62-
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof Event)) {
62+
} elseif (\is_string($event) && (null === $eventName || $eventName instanceof ContractsEvent || $eventName instanceof Event)) {
6363
@trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.', ContractsEventDispatcherInterface::class), E_USER_DEPRECATED);
6464
$swap = $event;
6565
$event = $eventName ?? new Event();

Tests/EventDispatcherTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,12 @@ public function testLegacySignatureWithEvent()
440440
$this->dispatcher->dispatch('foo', new Event());
441441
}
442442

443+
/**
444+
* @group legacy
445+
* @expectedDeprecation Calling the "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.
446+
*/
443447
public function testLegacySignatureWithNewEventObject()
444448
{
445-
$this->expectException('TypeError');
446-
$this->expectExceptionMessage('Argument 1 passed to "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" must be an object, string given.');
447449
$this->dispatcher->dispatch('foo', new ContractsEvent());
448450
}
449451
}

Tests/LegacyEventDispatcherProxyTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ public function testLegacySignatureWithEvent()
4141
$this->createEventDispatcher()->dispatch('foo', new Event());
4242
}
4343

44+
/**
45+
* @group legacy
46+
* @expectedDeprecation The signature of the "Symfony\Component\EventDispatcher\Tests\TestLegacyEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.
47+
* @expectedDeprecation The signature of the "Symfony\Component\EventDispatcher\Tests\TestLegacyEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.
48+
* @expectedDeprecation Calling the "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.
49+
*/
4450
public function testLegacySignatureWithNewEventObject()
4551
{
46-
$this->expectException('TypeError');
47-
$this->expectExceptionMessage('Argument 1 passed to "Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch()" must be an object, string given.');
4852
$this->createEventDispatcher()->dispatch('foo', new ContractsEvent());
4953
}
5054

0 commit comments

Comments
 (0)