From bd4c5f075f097672e9308faf5882cc806abee9bb Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 14 Jul 2020 10:08:00 +0100
Subject: [PATCH] Issue #3055194 by catch, mikelutz, longwave, mkalkbrenner,
 hchonov: [Symfony 5] The signature of the
 "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()"
 method should be updated to "dispatch($event, string $eventName = null)", not
 doing so is deprecated since Symfony 4.3

---
 .../ContainerAwareEventDispatcher.php         | 18 +++++++--
 .../Component/EventDispatcher/composer.json   |  3 +-
 core/lib/Drupal/Core/Config/Config.php        |  4 +-
 core/lib/Drupal/Core/Config/ConfigFactory.php |  2 +-
 .../lib/Drupal/Core/Config/ConfigImporter.php |  6 +--
 core/lib/Drupal/Core/Config/ConfigManager.php |  2 +-
 .../Core/Config/ExportStorageManager.php      |  2 +-
 .../Core/Config/ImportStorageTransformer.php  |  2 +-
 core/lib/Drupal/Core/DrupalKernel.php         |  3 +-
 .../Drupal/Core/Entity/EntityTypeListener.php | 10 ++---
 .../Field/FieldStorageDefinitionListener.php  |  6 +--
 .../Core/Render/MainContent/HtmlRenderer.php  |  2 +-
 core/lib/Drupal/Core/Routing/RouteBuilder.php |  6 +--
 core/lib/Drupal/Core/Session/AccountProxy.php |  2 +-
 core/modules/big_pipe/src/Render/BigPipe.php  |  2 +-
 .../src/BlockContentAccessControlHandler.php  |  2 +-
 .../src/ConfigNamesMapper.php                 |  2 +-
 .../ResourceType/ResourceTypeRepository.php   |  2 +-
 .../src/Config/LanguageConfigOverride.php     |  4 +-
 .../layout_builder/src/SectionComponent.php   |  2 +-
 .../tests/src/Unit/SectionComponentTest.php   |  4 +-
 core/modules/locale/locale.module             |  2 +-
 .../modules/migrate/src/MigrateExecutable.php | 16 ++++----
 .../migrate/src/Plugin/migrate/id_map/Sql.php |  9 ++---
 .../tests/src/Kernel/TimezoneResolverTest.php |  2 +-
 core/modules/user/src/UserFloodControl.php    |  2 +-
 ...sEntitySchemaSubscriberIntegrationTest.php |  2 +-
 .../ContainerAwareEventDispatcherTest.php     | 38 ++++++++++++-------
 .../RedirectResponseSubscriberTest.php        |  8 ++--
 .../Tests/Core/Routing/RouteBuilderTest.php   | 10 ++---
 .../Listeners/DeprecationListenerTrait.php    |  2 -
 31 files changed, 100 insertions(+), 77 deletions(-)

diff --git a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
index 2e790eea0417..59c165720ad4 100644
--- a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
+++ b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
@@ -6,6 +6,8 @@
 use Symfony\Component\EventDispatcher\Event;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
+use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
 
 /**
  * A performance optimized container aware event dispatcher.
@@ -86,9 +88,19 @@ public function __construct(ContainerInterface $container, array $listeners = []
   /**
    * {@inheritdoc}
    */
-  public function dispatch($event_name, Event $event = NULL) {
-    if ($event === NULL) {
-      $event = new Event();
+  public function dispatch($event/*, string $event_name = NULL*/) {
+    $event_name = 1 < \func_num_args() ? func_get_arg(1) : NULL;
+    if (\is_object($event)) {
+      $event_name = $event_name ?? \get_class($event);
+    }
+    elseif (\is_string($event) && (NULL === $event_name || $event_name instanceof ContractsEvent || $event_name instanceof Event)) {
+      @trigger_error('Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument is deprecated in drupal:9.1.0, an Event object will be required instead in drupal:10.0.0. See https://www.drupal.org/node/3154407', E_USER_DEPRECATED);
+      $swap = $event;
+      $event = $event_name ?? new Event();
+      $event_name = $swap;
+    }
+    else {
+      throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', ContractsEventDispatcherInterface::class, \gettype($event)));
     }
 
     if (isset($this->listeners[$event_name])) {
diff --git a/core/lib/Drupal/Component/EventDispatcher/composer.json b/core/lib/Drupal/Component/EventDispatcher/composer.json
index c75d3f101457..3574908ffbd7 100644
--- a/core/lib/Drupal/Component/EventDispatcher/composer.json
+++ b/core/lib/Drupal/Component/EventDispatcher/composer.json
@@ -7,7 +7,8 @@
   "require": {
     "php": ">=7.3.0",
     "symfony/dependency-injection": "^4.4",
-    "symfony/event-dispatcher": "^4.4"
+    "symfony/event-dispatcher": "^4.4",
+    "symfony/event-dispatcher-contracts": "^1.1"
   },
   "autoload": {
     "psr-4": {
diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php
index 0d66e8464ff7..026bb55e9fa2 100644
--- a/core/lib/Drupal/Core/Config/Config.php
+++ b/core/lib/Drupal/Core/Config/Config.php
@@ -228,7 +228,7 @@ public function save($has_trusted_data = FALSE) {
       Cache::invalidateTags($this->getCacheTags());
     }
     $this->isNew = FALSE;
-    $this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this));
+    $this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::SAVE);
     $this->originalData = $this->data;
     return $this;
   }
@@ -245,7 +245,7 @@ public function delete() {
     Cache::invalidateTags($this->getCacheTags());
     $this->isNew = TRUE;
     $this->resetOverriddenData();
-    $this->eventDispatcher->dispatch(ConfigEvents::DELETE, new ConfigCrudEvent($this));
+    $this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::DELETE);
     $this->originalData = $this->data;
     return $this;
   }
diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php
index fedd62a713e0..53e04d2785b2 100644
--- a/core/lib/Drupal/Core/Config/ConfigFactory.php
+++ b/core/lib/Drupal/Core/Config/ConfigFactory.php
@@ -260,7 +260,7 @@ public function rename($old_name, $new_name) {
 
     // Prime the cache and load the configuration with the correct overrides.
     $config = $this->get($new_name);
-    $this->eventDispatcher->dispatch(ConfigEvents::RENAME, new ConfigRenameEvent($config, $old_name));
+    $this->eventDispatcher->dispatch(new ConfigRenameEvent($config, $old_name), ConfigEvents::RENAME);
     return $this;
   }
 
diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php
index 0d3139f78a92..25b7d0afbbec 100644
--- a/core/lib/Drupal/Core/Config/ConfigImporter.php
+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -640,7 +640,7 @@ protected function processMissingContent(&$context) {
     if (!empty($missing_content)) {
       $event = new MissingContentEvent($missing_content);
       // Fire an event to allow listeners to create the missing content.
-      $this->eventDispatcher->dispatch(ConfigEvents::IMPORT_MISSING_CONTENT, $event);
+      $this->eventDispatcher->dispatch($event, ConfigEvents::IMPORT_MISSING_CONTENT);
       $sandbox['missing_content']['data'] = $event->getMissingContent();
     }
     $current_count = count($sandbox['missing_content']['data']);
@@ -660,7 +660,7 @@ protected function processMissingContent(&$context) {
    *   The batch context.
    */
   protected function finish(&$context) {
-    $this->eventDispatcher->dispatch(ConfigEvents::IMPORT, new ConfigImporterEvent($this));
+    $this->eventDispatcher->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT);
     // The import is now complete.
     $this->lock->release(static::LOCK_NAME);
     $this->reset();
@@ -742,7 +742,7 @@ public function validate() {
           $this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', ['@old_name' => $names['old_name'], '@new_name' => $names['new_name']]));
         }
       }
-      $this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this));
+      $this->eventDispatcher->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT_VALIDATE);
       if (count($this->getErrors())) {
         $errors = array_merge(['There were errors validating the config synchronization.'], $this->getErrors());
         throw new ConfigImporterException(implode(PHP_EOL, $errors));
diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php
index ec4c405b570a..71549978f35d 100644
--- a/core/lib/Drupal/Core/Config/ConfigManager.php
+++ b/core/lib/Drupal/Core/Config/ConfigManager.php
@@ -378,7 +378,7 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names
   public function getConfigCollectionInfo() {
     if (!isset($this->configCollectionInfo)) {
       $this->configCollectionInfo = new ConfigCollectionInfo();
-      $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_INFO, $this->configCollectionInfo);
+      $this->eventDispatcher->dispatch($this->configCollectionInfo, ConfigEvents::COLLECTION_INFO);
     }
     return $this->configCollectionInfo;
   }
diff --git a/core/lib/Drupal/Core/Config/ExportStorageManager.php b/core/lib/Drupal/Core/Config/ExportStorageManager.php
index 99c3f1fd15ed..aeaadedeb54d 100644
--- a/core/lib/Drupal/Core/Config/ExportStorageManager.php
+++ b/core/lib/Drupal/Core/Config/ExportStorageManager.php
@@ -85,7 +85,7 @@ public function getStorage() {
     }
 
     self::replaceStorageContents($this->active, $this->storage);
-    $this->eventDispatcher->dispatch(ConfigEvents::STORAGE_TRANSFORM_EXPORT, new StorageTransformEvent($this->storage));
+    $this->eventDispatcher->dispatch(new StorageTransformEvent($this->storage), ConfigEvents::STORAGE_TRANSFORM_EXPORT);
 
     return new ReadOnlyStorage($this->storage);
   }
diff --git a/core/lib/Drupal/Core/Config/ImportStorageTransformer.php b/core/lib/Drupal/Core/Config/ImportStorageTransformer.php
index 039516b31d47..fcd5a12d59b1 100644
--- a/core/lib/Drupal/Core/Config/ImportStorageTransformer.php
+++ b/core/lib/Drupal/Core/Config/ImportStorageTransformer.php
@@ -117,7 +117,7 @@ public function transform(StorageInterface $storage) {
     self::replaceStorageContents($storage, $mutable);
 
     // Dispatch the event so that event listeners can alter the configuration.
-    $this->eventDispatcher->dispatch(ConfigEvents::STORAGE_TRANSFORM_IMPORT, new StorageTransformEvent($mutable));
+    $this->eventDispatcher->dispatch(new StorageTransformEvent($mutable), ConfigEvents::STORAGE_TRANSFORM_IMPORT);
 
     // Return the storage with the altered configuration.
     return $mutable;
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index f952c3e1de4b..c52b1ec26f05 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -4,6 +4,7 @@
 
 use Composer\Autoload\ClassLoader;
 use Drupal\Component\Assertion\Handle;
+use Symfony\Component\EventDispatcher\Event;
 use Drupal\Component\FileCache\FileCacheFactory;
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\Cache\DatabaseBackend;
@@ -952,7 +953,7 @@ protected function initializeContainer() {
     // Allow other parts of the codebase to react on container initialization in
     // subrequest.
     if (!empty($subrequest)) {
-      $this->container->get('event_dispatcher')->dispatch(self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED);
+      $this->container->get('event_dispatcher')->dispatch(new Event(), self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED);
     }
 
     // If needs dumping flag was set, dump the container.
diff --git a/core/lib/Drupal/Core/Entity/EntityTypeListener.php b/core/lib/Drupal/Core/Entity/EntityTypeListener.php
index 258c9ffa6220..32e7f477109b 100644
--- a/core/lib/Drupal/Core/Entity/EntityTypeListener.php
+++ b/core/lib/Drupal/Core/Entity/EntityTypeListener.php
@@ -76,7 +76,7 @@ public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
       $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
     }
 
-    $this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
+    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
     $this->clearCachedDefinitions();
   }
 
@@ -98,7 +98,7 @@ public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, ar
       $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
     }
 
-    $this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
+    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
     $this->clearCachedDefinitions();
   }
 
@@ -119,7 +119,7 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
 
     $this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
 
-    $this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
+    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type, $original), EntityTypeEvents::UPDATE);
     $this->clearCachedDefinitions();
   }
 
@@ -142,7 +142,7 @@ public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
 
     $this->entityLastInstalledSchemaRepository->deleteLastInstalledDefinition($entity_type_id);
 
-    $this->eventDispatcher->dispatch(EntityTypeEvents::DELETE, new EntityTypeEvent($entity_type));
+    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::DELETE);
     $this->clearCachedDefinitions();
   }
 
@@ -165,7 +165,7 @@ public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, En
         $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
       }
 
-      $this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
+      $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type, $original), EntityTypeEvents::UPDATE);
       $this->clearCachedDefinitions();
     }
   }
diff --git a/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php b/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php
index b73f3411e5a2..8e52ec66423e 100644
--- a/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php
+++ b/core/lib/Drupal/Core/Field/FieldStorageDefinitionListener.php
@@ -87,7 +87,7 @@ public function onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $
 
     $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
 
-    $this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::CREATE, new FieldStorageDefinitionEvent($storage_definition));
+    $this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition), FieldStorageDefinitionEvents::CREATE);
     $this->entityFieldManager->clearCachedFieldDefinitions();
   }
 
@@ -106,7 +106,7 @@ public function onFieldStorageDefinitionUpdate(FieldStorageDefinitionInterface $
 
     $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
 
-    $this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::UPDATE, new FieldStorageDefinitionEvent($storage_definition, $original));
+    $this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition, $original), FieldStorageDefinitionEvents::UPDATE);
     $this->entityFieldManager->clearCachedFieldDefinitions();
   }
 
@@ -135,7 +135,7 @@ public function onFieldStorageDefinitionDelete(FieldStorageDefinitionInterface $
 
     $this->entityLastInstalledSchemaRepository->deleteLastInstalledFieldStorageDefinition($storage_definition);
 
-    $this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::DELETE, new FieldStorageDefinitionEvent($storage_definition));
+    $this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition), FieldStorageDefinitionEvents::DELETE);
     $this->entityFieldManager->clearCachedFieldDefinitions();
   }
 
diff --git a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
index 13e9c7675f3f..2b9f40e4c56f 100644
--- a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
+++ b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
@@ -206,7 +206,7 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte
       // Select the page display variant to be used to render this main content,
       // default to the built-in "simple page".
       $event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
-      $this->eventDispatcher->dispatch(RenderEvents::SELECT_PAGE_DISPLAY_VARIANT, $event);
+      $this->eventDispatcher->dispatch($event, RenderEvents::SELECT_PAGE_DISPLAY_VARIANT);
       $variant_id = $event->getPluginId();
 
       // We must render the main content now already, because it might provide a
diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php
index 16fd0bbcdf86..205e1c10de19 100644
--- a/core/lib/Drupal/Core/Routing/RouteBuilder.php
+++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php
@@ -181,12 +181,12 @@ public function rebuild() {
 
     // DYNAMIC is supposed to be used to add new routes based upon all the
     // static defined ones.
-    $this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection));
+    $this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::DYNAMIC);
 
     // ALTER is the final step to alter all the existing routes. We cannot stop
     // people from adding new routes here, but we define two separate steps to
     // make it clear.
-    $this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection));
+    $this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::ALTER);
 
     $this->checkProvider->setChecks($collection);
 
@@ -194,7 +194,7 @@ public function rebuild() {
     $this->dumper->dump();
 
     $this->lock->release('router_rebuild');
-    $this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
+    $this->dispatcher->dispatch(new Event(), RoutingEvents::FINISHED);
     $this->building = FALSE;
 
     $this->rebuildNeeded = FALSE;
diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php
index 779a97ef031d..2815c631526d 100644
--- a/core/lib/Drupal/Core/Session/AccountProxy.php
+++ b/core/lib/Drupal/Core/Session/AccountProxy.php
@@ -62,7 +62,7 @@ public function setAccount(AccountInterface $account) {
     }
     $this->account = $account;
     $this->id = $account->id();
-    $this->eventDispatcher->dispatch(AccountEvents::SET_USER, new AccountSetEvent($account));
+    $this->eventDispatcher->dispatch(new AccountSetEvent($account), AccountEvents::SET_USER);
   }
 
   /**
diff --git a/core/modules/big_pipe/src/Render/BigPipe.php b/core/modules/big_pipe/src/Render/BigPipe.php
index 6913dbfb335a..f21640bc4e5c 100644
--- a/core/modules/big_pipe/src/Render/BigPipe.php
+++ b/core/modules/big_pipe/src/Render/BigPipe.php
@@ -649,7 +649,7 @@ protected function filterResponse(Request $request, $request_type, Response $res
     assert($request_type === HttpKernelInterface::MASTER_REQUEST || $request_type === HttpKernelInterface::SUB_REQUEST);
     $this->requestStack->push($request);
     $event = new ResponseEvent($this->httpKernel, $request, $request_type, $response);
-    $this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
+    $this->eventDispatcher->dispatch($event, KernelEvents::RESPONSE);
     $filtered_response = $event->getResponse();
     $this->requestStack->pop();
     return $filtered_response;
diff --git a/core/modules/block_content/src/BlockContentAccessControlHandler.php b/core/modules/block_content/src/BlockContentAccessControlHandler.php
index 00f05151b06f..0c84190997fa 100644
--- a/core/modules/block_content/src/BlockContentAccessControlHandler.php
+++ b/core/modules/block_content/src/BlockContentAccessControlHandler.php
@@ -73,7 +73,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
       if (empty($dependency)) {
         // If an access dependency has not been set let modules set one.
         $event = new BlockContentGetDependencyEvent($entity);
-        $this->eventDispatcher->dispatch(BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY, $event);
+        $this->eventDispatcher->dispatch($event, BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY);
         $dependency = $event->getAccessDependency();
         if (empty($dependency)) {
           return AccessResult::forbidden("Non-reusable blocks must set an access dependency for access control.");
diff --git a/core/modules/config_translation/src/ConfigNamesMapper.php b/core/modules/config_translation/src/ConfigNamesMapper.php
index d63807a26f44..188fd6fc6728 100644
--- a/core/modules/config_translation/src/ConfigNamesMapper.php
+++ b/core/modules/config_translation/src/ConfigNamesMapper.php
@@ -384,7 +384,7 @@ public function populateFromRouteMatch(RouteMatchInterface $route_match) {
     $this->langcode = $route_match->getParameter('langcode');
 
     $event = new ConfigMapperPopulateEvent($this, $route_match);
-    $this->eventDispatcher->dispatch(ConfigTranslationEvents::POPULATE_MAPPER, $event);
+    $this->eventDispatcher->dispatch($event, ConfigTranslationEvents::POPULATE_MAPPER);
   }
 
   /**
diff --git a/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php b/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php
index ff830f4f5566..84aa71864c19 100644
--- a/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php
+++ b/core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php
@@ -154,7 +154,7 @@ protected function createResourceType(EntityTypeInterface $entity_type, $bundle)
     $fields = static::getFields($raw_fields, $entity_type, $bundle);
     if (!$internalize_resource_type) {
       $event = ResourceTypeBuildEvent::createFromEntityTypeAndBundle($entity_type, $bundle, $fields);
-      $this->eventDispatcher->dispatch(ResourceTypeBuildEvents::BUILD, $event);
+      $this->eventDispatcher->dispatch($event, ResourceTypeBuildEvents::BUILD);
       $internalize_resource_type = $event->resourceTypeShouldBeDisabled();
       $fields = $event->getFields();
     }
diff --git a/core/modules/language/src/Config/LanguageConfigOverride.php b/core/modules/language/src/Config/LanguageConfigOverride.php
index 6effe238fa39..01cd56c7e615 100644
--- a/core/modules/language/src/Config/LanguageConfigOverride.php
+++ b/core/modules/language/src/Config/LanguageConfigOverride.php
@@ -62,7 +62,7 @@ public function save($has_trusted_data = FALSE) {
     // an update of configuration, but only for a specific language.
     Cache::invalidateTags($this->getCacheTags());
     $this->isNew = FALSE;
-    $this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::SAVE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this));
+    $this->eventDispatcher->dispatch(new LanguageConfigOverrideCrudEvent($this), LanguageConfigOverrideEvents::SAVE_OVERRIDE);
     $this->originalData = $this->data;
     return $this;
   }
@@ -75,7 +75,7 @@ public function delete() {
     $this->storage->delete($this->name);
     Cache::invalidateTags($this->getCacheTags());
     $this->isNew = TRUE;
-    $this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::DELETE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this));
+    $this->eventDispatcher->dispatch(new LanguageConfigOverrideCrudEvent($this), LanguageConfigOverrideEvents::DELETE_OVERRIDE);
     $this->originalData = $this->data;
     return $this;
   }
diff --git a/core/modules/layout_builder/src/SectionComponent.php b/core/modules/layout_builder/src/SectionComponent.php
index 4003f7e7e7de..c09492e3ab56 100644
--- a/core/modules/layout_builder/src/SectionComponent.php
+++ b/core/modules/layout_builder/src/SectionComponent.php
@@ -87,7 +87,7 @@ public function __construct($uuid, $region, array $configuration = [], array $ad
    */
   public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
     $event = new SectionComponentBuildRenderArrayEvent($this, $contexts, $in_preview);
-    $this->eventDispatcher()->dispatch(LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY, $event);
+    $this->eventDispatcher()->dispatch($event, LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY);
     $output = $event->getBuild();
     $event->getCacheableMetadata()->applyTo($output);
     return $output;
diff --git a/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
index 48a24778c1ab..ca2138ec9ee7 100644
--- a/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
+++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
@@ -33,11 +33,11 @@ public function testToRenderArray() {
     // Imitate an event subscriber by setting a resulting build on the event.
     $event_dispatcher = $this->prophesize(EventDispatcherInterface::class);
     $event_dispatcher
-      ->dispatch(LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY, Argument::type(SectionComponentBuildRenderArrayEvent::class))
+      ->dispatch(Argument::type(SectionComponentBuildRenderArrayEvent::class), LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY)
       ->shouldBeCalled()
       ->will(function ($args) {
         /** @var \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event */
-        $event = $args[1];
+        $event = $args[0];
         $event->setBuild(['#markup' => $event->getPlugin()->getPluginId()]);
         return;
       });
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 663abd134ab3..71e694171037 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -1057,7 +1057,7 @@ function _locale_refresh_translations($langcodes, $lids = []) {
   }
 
   // Throw locale.save_translation event.
-  \Drupal::service('event_dispatcher')->dispatch(LocaleEvents::SAVE_TRANSLATION, new LocaleEvent($langcodes, $lids));
+  \Drupal::service('event_dispatcher')->dispatch(new LocaleEvent($langcodes, $lids), LocaleEvents::SAVE_TRANSLATION);
 }
 
 /**
diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php
index c3a0506419d5..c8d22c55b9ee 100644
--- a/core/modules/migrate/src/MigrateExecutable.php
+++ b/core/modules/migrate/src/MigrateExecutable.php
@@ -157,7 +157,7 @@ public function import() {
         ]), 'error');
       return MigrationInterface::RESULT_FAILED;
     }
-    $this->getEventDispatcher()->dispatch(MigrateEvents::PRE_IMPORT, new MigrateImportEvent($this->migration, $this->message));
+    $this->getEventDispatcher()->dispatch(new MigrateImportEvent($this->migration, $this->message), MigrateEvents::PRE_IMPORT);
 
     // Knock off migration if the requirements haven't been met.
     try {
@@ -220,11 +220,11 @@ public function import() {
 
       if ($save) {
         try {
-          $this->getEventDispatcher()->dispatch(MigrateEvents::PRE_ROW_SAVE, new MigratePreRowSaveEvent($this->migration, $this->message, $row));
+          $this->getEventDispatcher()->dispatch(new MigratePreRowSaveEvent($this->migration, $this->message, $row), MigrateEvents::PRE_ROW_SAVE);
           $destination_ids = $id_map->lookupDestinationIds($this->sourceIdValues);
           $destination_id_values = $destination_ids ? reset($destination_ids) : [];
           $destination_id_values = $destination->import($row, $destination_id_values);
-          $this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROW_SAVE, new MigratePostRowSaveEvent($this->migration, $this->message, $row, $destination_id_values));
+          $this->getEventDispatcher()->dispatch(new MigratePostRowSaveEvent($this->migration, $this->message, $row, $destination_id_values), MigrateEvents::POST_ROW_SAVE);
           if ($destination_id_values) {
             // We do not save an idMap entry for config.
             if ($destination_id_values !== TRUE) {
@@ -276,7 +276,7 @@ public function import() {
       }
     }
 
-    $this->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration, $this->message));
+    $this->getEventDispatcher()->dispatch(new MigrateImportEvent($this->migration, $this->message), MigrateEvents::POST_IMPORT);
     $this->migration->setStatus(MigrationInterface::STATUS_IDLE);
     return $return;
   }
@@ -292,7 +292,7 @@ public function rollback() {
     }
 
     // Announce that rollback is about to happen.
-    $this->getEventDispatcher()->dispatch(MigrateEvents::PRE_ROLLBACK, new MigrateRollbackEvent($this->migration));
+    $this->getEventDispatcher()->dispatch(new MigrateRollbackEvent($this->migration), MigrateEvents::PRE_ROLLBACK);
 
     // Optimistically assume things are going to work out; if not, $return will be
     // updated to some other status.
@@ -310,10 +310,10 @@ public function rollback() {
         $map_row = $id_map->getRowByDestination($destination_key);
         if ($map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) {
           $this->getEventDispatcher()
-            ->dispatch(MigrateEvents::PRE_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
+            ->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::PRE_ROW_DELETE);
           $destination->rollback($destination_key);
           $this->getEventDispatcher()
-            ->dispatch(MigrateEvents::POST_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
+            ->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::POST_ROW_DELETE);
         }
         // We're now done with this row, so remove it from the map.
         $id_map->deleteDestination($destination_key);
@@ -340,7 +340,7 @@ public function rollback() {
     }
 
     // Notify modules that rollback attempt was complete.
-    $this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($this->migration));
+    $this->getEventDispatcher()->dispatch(new MigrateRollbackEvent($this->migration), MigrateEvents::POST_ROLLBACK);
     $this->migration->setStatus(MigrationInterface::STATUS_IDLE);
 
     return $return;
diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
index 26c56f417a78..6675ec8947fb 100644
--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -645,7 +645,7 @@ public function saveIdMapping(Row $row, array $destination_id_values, $source_ro
     }
     $keys = [$this::SOURCE_IDS_HASH => $this->getSourceIdsHash($source_id_values)];
     // Notify anyone listening of the map row we're about to save.
-    $this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $fields));
+    $this->eventDispatcher->dispatch(new MigrateMapSaveEvent($this, $fields), MigrateEvents::MAP_SAVE);
     $this->getDatabase()->merge($this->mapTableName())
       ->key($keys)
       ->fields($fields)
@@ -670,8 +670,7 @@ public function saveMessage(array $source_id_values, $message, $level = Migratio
       ->execute();
 
     // Notify anyone listening of the message we've saved.
-    $this->eventDispatcher->dispatch(MigrateEvents::IDMAP_MESSAGE,
-      new MigrateIdMapMessageEvent($this->migration, $source_id_values, $message, $level));
+    $this->eventDispatcher->dispatch(new MigrateIdMapMessageEvent($this->migration, $source_id_values, $message, $level), MigrateEvents::IDMAP_MESSAGE);
   }
 
   /**
@@ -785,7 +784,7 @@ public function delete(array $source_id_values, $messages_only = FALSE) {
       $map_query = $this->getDatabase()->delete($this->mapTableName());
       $map_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
       // Notify anyone listening of the map row we're about to delete.
-      $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
+      $this->eventDispatcher->dispatch(new MigrateMapDeleteEvent($this, $source_id_values), MigrateEvents::MAP_DELETE);
       $map_query->execute();
     }
     $message_query = $this->getDatabase()->delete($this->messageTableName());
@@ -805,7 +804,7 @@ public function deleteDestination(array $destination_id_values) {
         $map_query->condition($destination_id, $destination_id_values[$field_name]);
       }
       // Notify anyone listening of the map row we're about to delete.
-      $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
+      $this->eventDispatcher->dispatch(new MigrateMapDeleteEvent($this, $source_id_values), MigrateEvents::MAP_DELETE);
       $map_query->execute();
 
       $message_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
diff --git a/core/modules/system/tests/src/Kernel/TimezoneResolverTest.php b/core/modules/system/tests/src/Kernel/TimezoneResolverTest.php
index 58bc309f388b..d9a29332e5e6 100644
--- a/core/modules/system/tests/src/Kernel/TimezoneResolverTest.php
+++ b/core/modules/system/tests/src/Kernel/TimezoneResolverTest.php
@@ -45,7 +45,7 @@ public function testGetTimeZone() {
     $eventDispatcher = $this->container->get('event_dispatcher');
     $kernel = $this->container->get('kernel');
 
-    $eventDispatcher->dispatch(KernelEvents::REQUEST, new RequestEvent($kernel, Request::create('http://www.example.com'), HttpKernelInterface::MASTER_REQUEST));
+    $eventDispatcher->dispatch(new RequestEvent($kernel, Request::create('http://www.example.com'), HttpKernelInterface::MASTER_REQUEST, KernelEvents::REQUEST));
 
     $this->assertEquals('Australia/Adelaide', date_default_timezone_get());
 
diff --git a/core/modules/user/src/UserFloodControl.php b/core/modules/user/src/UserFloodControl.php
index c6d6bc07ddd8..c5f79b7bf727 100644
--- a/core/modules/user/src/UserFloodControl.php
+++ b/core/modules/user/src/UserFloodControl.php
@@ -69,7 +69,7 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL)
         $identifier = $this->requestStack->getCurrentRequest()->getClientIp();
       }
       $event = new UserFloodEvent($name, $threshold, $window, $identifier);
-      $this->eventDispatcher->dispatch($event_map[$name], $event);
+      $this->eventDispatcher->dispatch($event, $event_map[$name]);
     }
     return FALSE;
   }
diff --git a/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php b/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php
index 89bb7bd2007c..fec962da5880 100644
--- a/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php
+++ b/core/modules/views/tests/src/Kernel/EventSubscriber/ViewsEntitySchemaSubscriberIntegrationTest.php
@@ -107,7 +107,7 @@ public function testDeleteEntityType() {
     $this->assertTrue(isset($views['test_view_entity_test_additional_base_field']));
 
     $event = new EntityTypeEvent($this->entityTypeManager->getDefinition('entity_test_update'));
-    $this->eventDispatcher->dispatch(EntityTypeEvents::DELETE, $event);
+    $this->eventDispatcher->dispatch($event, EntityTypeEvents::DELETE);
 
     // We expect that views which use 'entity_test_update' as base tables are
     // disabled.
diff --git a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
index 33a44087c267..facac8776afa 100644
--- a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
+++ b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
@@ -110,7 +110,7 @@ public function testDispatchWithCallables() {
     ];
 
     $dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
-    $dispatcher->dispatch('test_event');
+    $dispatcher->dispatch(new Event(), 'test_event');
 
     $this->assertTrue($thirdListener[0]->preFooInvoked);
   }
@@ -140,6 +140,18 @@ public function testGetListenersWithServices() {
     $this->assertSame($expectedListeners, $actualListeners);
   }
 
+  /**
+   * Tests argument order deprecation.
+   *
+   * @group legacy
+   * @expectedDeprecation Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument is deprecated in drupal:9.1.0, an Event object will be required instead in drupal:10.0.0. See https://www.drupal.org/node/3154407
+   */
+  public function testDispatchArgumentOrderDeprecation() {
+    $container = new ContainerBuilder();
+    $dispatcher = new ContainerAwareEventDispatcher($container, []);
+    $dispatcher->dispatch('foo');
+  }
+
   public function testDispatchWithServices() {
     $container = new ContainerBuilder();
     $container->register('listener_service', TestEventListener::class);
@@ -154,7 +166,7 @@ public function testDispatchWithServices() {
 
     $dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
 
-    $dispatcher->dispatch('test_event');
+    $dispatcher->dispatch(new Event(), 'test_event');
 
     $listenerService = $container->get('listener_service');
     $this->assertTrue($listenerService->preFooInvoked);
@@ -183,7 +195,7 @@ public function testRemoveService() {
     // listener service.
     $this->assertFalse($container->initialized('other_listener_service'));
 
-    $dispatcher->dispatch('test_event');
+    $dispatcher->dispatch(new Event(), 'test_event');
 
     $this->assertFalse($listenerService->preFooInvoked);
     $otherService = $container->get('other_listener_service');
@@ -287,13 +299,13 @@ public function testGetListenerPriority() {
   public function testDispatch() {
     $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
     $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
-    $this->dispatcher->dispatch(self::PREFOO);
+    $this->dispatcher->dispatch(new Event(), self::PREFOO);
     $this->assertTrue($this->listener->preFooInvoked);
     $this->assertFalse($this->listener->postFooInvoked);
-    $this->assertInstanceOf(Event::class, $this->dispatcher->dispatch('noevent'));
-    $this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(self::PREFOO));
+    $this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(new Event(), 'noevent'));
+    $this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(new Event(), self::PREFOO));
     $event = new Event();
-    $return = $this->dispatcher->dispatch(self::PREFOO, $event);
+    $return = $this->dispatcher->dispatch($event, self::PREFOO);
     $this->assertSame($event, $return);
   }
 
@@ -304,7 +316,7 @@ public function testDispatchForClosure() {
     };
     $this->dispatcher->addListener('pre.foo', $listener);
     $this->dispatcher->addListener('post.foo', $listener);
-    $this->dispatcher->dispatch(self::PREFOO);
+    $this->dispatcher->dispatch(new Event(), self::PREFOO);
     $this->assertEquals(1, $invoked);
   }
 
@@ -316,7 +328,7 @@ public function testStopEventPropagation() {
     // Manually set priority to enforce $this->listener to be called first
     $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10);
     $this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']);
-    $this->dispatcher->dispatch(self::POSTFOO);
+    $this->dispatcher->dispatch(new Event(), self::POSTFOO);
     $this->assertTrue($this->listener->postFooInvoked);
     $this->assertFalse($otherListener->postFooInvoked);
   }
@@ -335,7 +347,7 @@ public function testDispatchByPriority() {
     $this->dispatcher->addListener('pre.foo', $listener1, -10);
     $this->dispatcher->addListener('pre.foo', $listener2);
     $this->dispatcher->addListener('pre.foo', $listener3, 10);
-    $this->dispatcher->dispatch(self::PREFOO);
+    $this->dispatcher->dispatch(new Event(), self::PREFOO);
     $this->assertEquals(['3', '2', '1'], $invoked);
   }
 
@@ -409,7 +421,7 @@ public function testEventReceivesTheDispatcherInstanceAsArgument() {
     $this->dispatcher->addListener('test', [$listener, 'foo']);
     $this->assertNull($listener->name);
     $this->assertNull($listener->dispatcher);
-    $this->dispatcher->dispatch('test');
+    $this->dispatcher->dispatch(new Event(), 'test');
     $this->assertEquals('test', $listener->name);
     $this->assertSame($this->dispatcher, $listener->dispatcher);
   }
@@ -477,8 +489,8 @@ public function testDispatchLazyListener() {
     };
     $this->dispatcher->addListener('foo', [$factory, 'foo']);
     $this->assertSame(0, $called);
-    $this->dispatcher->dispatch('foo', new Event());
-    $this->dispatcher->dispatch('foo', new Event());
+    $this->dispatcher->dispatch(new Event(), 'foo');
+    $this->dispatcher->dispatch(new Event(), 'foo');
     $this->assertSame(1, $called);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
index 446805b6e47b..38c8ee276aa2 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
@@ -84,7 +84,7 @@ public function testDestinationRedirect(Request $request, $expected) {
     $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
-    $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
+    $dispatcher->dispatch($event, KernelEvents::RESPONSE);
 
     $target_url = $event->getResponse()->getTargetUrl();
     if ($expected) {
@@ -125,7 +125,7 @@ public function testDestinationRedirectToExternalUrl($request, $expected) {
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
     $this->expectException(Error::class);
-    $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
+    $dispatcher->dispatch($event, KernelEvents::RESPONSE);
   }
 
   /**
@@ -141,7 +141,7 @@ public function testRedirectWithOptInExternalUrl() {
     $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
-    $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
+    $dispatcher->dispatch($event, KernelEvents::RESPONSE);
 
     $target_url = $event->getResponse()->getTargetUrl();
     $this->assertEquals('http://external-url.com', $target_url);
@@ -173,7 +173,7 @@ public function testDestinationRedirectWithInvalidUrl(Request $request) {
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
     $this->expectException(Error::class);
-    $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
+    $dispatcher->dispatch($event, KernelEvents::RESPONSE);
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php
index cb8ed157a29f..7682bfdd0f27 100644
--- a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php
@@ -161,11 +161,11 @@ public function testRebuildWithStaticModuleRoutes() {
     // Ensure that the alter routes events are fired.
     $this->dispatcher->expects($this->at(0))
       ->method('dispatch')
-      ->with(RoutingEvents::DYNAMIC, $route_build_event);
+      ->with($route_build_event, RoutingEvents::DYNAMIC);
 
     $this->dispatcher->expects($this->at(1))
       ->method('dispatch')
-      ->with(RoutingEvents::ALTER, $route_build_event);
+      ->with($route_build_event, RoutingEvents::ALTER);
 
     // Ensure that access checks are set.
     $this->checkProvider->expects($this->once())
@@ -231,11 +231,11 @@ public function testRebuildWithProviderBasedRoutes() {
     // Ensure that the alter routes events are fired.
     $this->dispatcher->expects($this->at(0))
       ->method('dispatch')
-      ->with(RoutingEvents::DYNAMIC, $route_build_event);
+      ->with($route_build_event, RoutingEvents::DYNAMIC);
 
     $this->dispatcher->expects($this->at(1))
       ->method('dispatch')
-      ->with(RoutingEvents::ALTER, $route_build_event);
+      ->with($route_build_event, RoutingEvents::ALTER);
 
     // Ensure that access checks are set.
     $this->checkProvider->expects($this->once())
@@ -314,7 +314,7 @@ public function testRebuildWithOverriddenRouteClass() {
     $route_build_event = new RouteBuildEvent($route_collection_filled);
     $this->dispatcher->expects($this->at(0))
       ->method('dispatch')
-      ->with(RoutingEvents::DYNAMIC, $route_build_event);
+      ->with($route_build_event, RoutingEvents::DYNAMIC);
 
     $this->assertTrue($this->routeBuilder->rebuild());
   }
diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
index 1879bcd3df48..8b6ec6b62171 100644
--- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -149,8 +149,6 @@ public static function getSkippedDeprecations() {
       'The "Drupal\Core\File\MimeType\MimeTypeGuesser" class implements "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface" that is deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead.',
       'The "Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\FileBinaryMimeTypeGuesser" instead.',
       'The "Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\FileinfoMimeTypeGuesser" instead.',
-      'The signature of the "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.',
-      '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.',
       'The "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its interface "Symfony\Contracts\EventDispatcher\EventDispatcherInterface", not defining it is deprecated.',
       'The "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its parent class "Symfony\Contracts\EventDispatcher\EventDispatcherInterface", not defining it is deprecated.',
       'Passing a command as string when creating a "Symfony\Component\Process\Process" instance is deprecated since Symfony 4.2, pass it as an array of its arguments instead, or use the "Process::fromShellCommandline()" constructor if you need features provided by the shell.',
-- 
GitLab