From c8a0ed4b4da1059735058e56bdca455512456b83 Mon Sep 17 00:00:00 2001
From: Oliver Klee <typo3-coding@oliverklee.de>
Date: Sat, 12 Nov 2022 14:59:13 +0100
Subject: [PATCH] [TASK] Make the `NoopEventDispatcher` available to extensions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With the class moved out of the `Tests` namespace into the general
`EventDispatcher` namespace, extensions can now also use this class
for their tests.

Also add unit tests for the moved class.

Resolves: #99070
Releases: main, 11.5
Change-Id: I69b94f50f68dcacfe036e8eb489ba6b82fbb585a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76569
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
---
 .../Unit/Controller/LoginControllerTest.php   |  2 +-
 .../DatabaseUserPermissionCheckTest.php       |  2 +-
 .../Tests/Unit/Module/ModuleFactoryTest.php   |  2 +-
 .../Tests/Unit/Module/ModuleRegistryTest.php  |  2 +-
 .../Tests/Unit/Utility/BackendUtilityTest.php |  2 +-
 .../EventDispatcher/NoopEventDispatcher.php   | 10 ++++-
 .../Resource/ResourceStorageTest.php          |  2 +-
 .../Configuration/SiteConfigurationTest.php   |  2 +-
 .../NoopEventDispatcherTest.php               | 42 +++++++++++++++++++
 .../Unit/Resource/MetaDataAspectTest.php      |  2 +-
 .../Unit/Resource/StorageRepositoryTest.php   |  2 +-
 .../AST/AstBuilderInterfaceTest.php           |  2 +-
 .../Unit/Utility/DependencyUtilityTest.php    |  2 +-
 .../Tests/Unit/Http/RequestHandlerTest.php    |  2 +-
 .../Utility/ImportExportUtilityTest.php       |  2 +-
 15 files changed, 63 insertions(+), 15 deletions(-)
 rename typo3/sysext/core/{Tests/Unit/Fixtures => Classes}/EventDispatcher/NoopEventDispatcher.php (66%)
 create mode 100644 typo3/sysext/core/Tests/Unit/EventDispatcher/NoopEventDispatcherTest.php

diff --git a/typo3/sysext/backend/Tests/Unit/Controller/LoginControllerTest.php b/typo3/sysext/backend/Tests/Unit/Controller/LoginControllerTest.php
index e5718e714afe..24b1c0794b29 100644
--- a/typo3/sysext/backend/Tests/Unit/Controller/LoginControllerTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Controller/LoginControllerTest.php
@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
 use TYPO3\CMS\Core\Configuration\Features;
 use TYPO3\CMS\Core\Context\Context;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\FormProtection\BackendFormProtection;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\Http\ServerRequest;
@@ -31,7 +32,6 @@ use TYPO3\CMS\Core\Information\Typo3Information;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Routing\BackendEntryPointResolver;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 class LoginControllerTest extends UnitTestCase
diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseUserPermissionCheckTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseUserPermissionCheckTest.php
index 8b5b870c780c..b7d8f88b03ea 100644
--- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseUserPermissionCheckTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseUserPermissionCheckTest.php
@@ -29,8 +29,8 @@ use TYPO3\CMS\Backend\Form\Exception\AccessDeniedRootNodeException;
 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedTableModifyException;
 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseUserPermissionCheck;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
diff --git a/typo3/sysext/backend/Tests/Unit/Module/ModuleFactoryTest.php b/typo3/sysext/backend/Tests/Unit/Module/ModuleFactoryTest.php
index af8a4a1d909d..f298600eca45 100644
--- a/typo3/sysext/backend/Tests/Unit/Module/ModuleFactoryTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Module/ModuleFactoryTest.php
@@ -18,8 +18,8 @@ declare(strict_types=1);
 namespace TYPO3\CMS\Backend\Tests\Unit\Module;
 
 use TYPO3\CMS\Backend\Module\ModuleFactory;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Imaging\IconRegistry;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 class ModuleFactoryTest extends UnitTestCase
diff --git a/typo3/sysext/backend/Tests/Unit/Module/ModuleRegistryTest.php b/typo3/sysext/backend/Tests/Unit/Module/ModuleRegistryTest.php
index 46c418ca06ed..f03b6fa89143 100644
--- a/typo3/sysext/backend/Tests/Unit/Module/ModuleRegistryTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Module/ModuleRegistryTest.php
@@ -20,8 +20,8 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Module;
 use TYPO3\CMS\Backend\Module\ModuleFactory;
 use TYPO3\CMS\Backend\Module\ModuleInterface;
 use TYPO3\CMS\Backend\Module\ModuleRegistry;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Imaging\IconRegistry;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 class ModuleRegistryTest extends UnitTestCase
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php b/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
index 041d229018d8..f3577846800c 100644
--- a/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
@@ -28,10 +28,10 @@ use TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader;
 use TYPO3\CMS\Core\Configuration\PageTsConfig;
 use TYPO3\CMS\Core\Configuration\Parser\PageTsConfigParser;
 use TYPO3\CMS\Core\Database\RelationHandler;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\CMS\Core\Site\SiteFinder;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
diff --git a/typo3/sysext/core/Tests/Unit/Fixtures/EventDispatcher/NoopEventDispatcher.php b/typo3/sysext/core/Classes/EventDispatcher/NoopEventDispatcher.php
similarity index 66%
rename from typo3/sysext/core/Tests/Unit/Fixtures/EventDispatcher/NoopEventDispatcher.php
rename to typo3/sysext/core/Classes/EventDispatcher/NoopEventDispatcher.php
index 7f4d2477d89f..2fd1a6df3446 100644
--- a/typo3/sysext/core/Tests/Unit/Fixtures/EventDispatcher/NoopEventDispatcher.php
+++ b/typo3/sysext/core/Classes/EventDispatcher/NoopEventDispatcher.php
@@ -15,13 +15,19 @@ declare(strict_types=1);
  * The TYPO3 project - inspiring people to share!
  */
 
-namespace TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher;
+namespace TYPO3\CMS\Core\EventDispatcher;
 
 use Psr\EventDispatcher\EventDispatcherInterface;
 
+/**
+ * An event dispatcher that does nothing. Useful for testing.
+ *
+ * Also used in scopes like the install tool where classes have dependencies
+ * to EventDispatcherInterface but should not actively dispatch events.
+ */
 final class NoopEventDispatcher implements EventDispatcherInterface
 {
-    public function dispatch(object $event)
+    public function dispatch(object $event): object
     {
         return $event;
     }
diff --git a/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php
index c2db4498f38f..4be2c8450b22 100644
--- a/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php
+++ b/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php
@@ -17,13 +17,13 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Core\Tests\Functional\Resource;
 
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Resource\Driver\AbstractDriver;
 use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
 
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/SiteConfigurationTest.php b/typo3/sysext/core/Tests/Unit/Configuration/SiteConfigurationTest.php
index ab096af75bc2..0a2b10450e15 100644
--- a/typo3/sysext/core/Tests/Unit/Configuration/SiteConfigurationTest.php
+++ b/typo3/sysext/core/Tests/Unit/Configuration/SiteConfigurationTest.php
@@ -22,8 +22,8 @@ use TYPO3\CMS\Core\Cache\Frontend\NullFrontend;
 use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
 use TYPO3\CMS\Core\Configuration\SiteConfiguration;
 use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Http\Uri;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
diff --git a/typo3/sysext/core/Tests/Unit/EventDispatcher/NoopEventDispatcherTest.php b/typo3/sysext/core/Tests/Unit/EventDispatcher/NoopEventDispatcherTest.php
new file mode 100644
index 000000000000..8db72d3f8c9d
--- /dev/null
+++ b/typo3/sysext/core/Tests/Unit/EventDispatcher/NoopEventDispatcherTest.php
@@ -0,0 +1,42 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+namespace TYPO3\CMS\Core\Tests\Unit\EventDispatcher;
+
+use Psr\EventDispatcher\EventDispatcherInterface;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+class NoopEventDispatcherTest extends UnitTestCase
+{
+    /**
+     * @test
+     */
+    public function implementsEventDispatcherInterface(): void
+    {
+        self::assertInstanceOf(EventDispatcherInterface::class, new NoopEventDispatcher());
+    }
+
+    /**
+     * @test
+     */
+    public function dispatchReturnsProvidedEvent(): void
+    {
+        $event = new \stdClass();
+        self::assertSame($event, (new NoopEventDispatcher())->dispatch($event));
+    }
+}
diff --git a/typo3/sysext/core/Tests/Unit/Resource/MetaDataAspectTest.php b/typo3/sysext/core/Tests/Unit/Resource/MetaDataAspectTest.php
index 1940a2a5ca8c..566dac3587bd 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/MetaDataAspectTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/MetaDataAspectTest.php
@@ -20,12 +20,12 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
 use PHPUnit\Framework\MockObject\MockObject;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Resource\Exception\InvalidUidException;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Index\MetaDataRepository;
 use TYPO3\CMS\Core\Resource\MetaDataAspect;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
diff --git a/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php b/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php
index a6d03eb7bc50..bafca2431adf 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php
@@ -17,11 +17,11 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
 
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Resource\Driver\AbstractDriver;
 use TYPO3\CMS\Core\Resource\Driver\DriverRegistry;
 use TYPO3\CMS\Core\Resource\LocalPath;
 use TYPO3\CMS\Core\Resource\StorageRepository;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 class StorageRepositoryTest extends UnitTestCase
diff --git a/typo3/sysext/core/Tests/Unit/TypoScript/AST/AstBuilderInterfaceTest.php b/typo3/sysext/core/Tests/Unit/TypoScript/AST/AstBuilderInterfaceTest.php
index 7eec3383f92d..ce23aec2ad51 100644
--- a/typo3/sysext/core/Tests/Unit/TypoScript/AST/AstBuilderInterfaceTest.php
+++ b/typo3/sysext/core/Tests/Unit/TypoScript/AST/AstBuilderInterfaceTest.php
@@ -17,7 +17,7 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Core\Tests\Unit\TypoScript\AST;
 
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\TypoScript\AST\AstBuilder;
 use TYPO3\CMS\Core\TypoScript\AST\CommentAwareAstBuilder;
 use TYPO3\CMS\Core\TypoScript\AST\Node\ChildNode;
diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Utility/DependencyUtilityTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Utility/DependencyUtilityTest.php
index df04a55e12de..e39ccd85ebbb 100644
--- a/typo3/sysext/extensionmanager/Tests/Unit/Utility/DependencyUtilityTest.php
+++ b/typo3/sysext/extensionmanager/Tests/Unit/Utility/DependencyUtilityTest.php
@@ -17,7 +17,7 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
 
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Extensionmanager\Domain\Model\Dependency;
 use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
 use TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository;
diff --git a/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php b/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php
index b6948fbe58ee..ead448992eae 100644
--- a/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php
+++ b/typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php
@@ -19,12 +19,12 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Http;
 
 use Symfony\Component\DependencyInjection\Container;
 use TYPO3\CMS\Core\EventDispatcher\ListenerProvider;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Http\ServerRequestFactory;
 use TYPO3\CMS\Core\Information\Typo3Information;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Site\Entity\Site;
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\TypoScript\AST\Node\RootNode;
 use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
diff --git a/typo3/sysext/impexp/Tests/Functional/Utility/ImportExportUtilityTest.php b/typo3/sysext/impexp/Tests/Functional/Utility/ImportExportUtilityTest.php
index 907a59cd91be..b82ca7a47721 100644
--- a/typo3/sysext/impexp/Tests/Functional/Utility/ImportExportUtilityTest.php
+++ b/typo3/sysext/impexp/Tests/Functional/Utility/ImportExportUtilityTest.php
@@ -17,7 +17,7 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Impexp\Tests\Functional\Utility;
 
-use TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\NoopEventDispatcher;
+use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
 use TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase;
 use TYPO3\CMS\Impexp\Utility\ImportExportUtility;
 
-- 
GitLab