From 4c0b36502ea9eb5c70ef4b1d951c8478c33af883 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 7 Aug 2023 18:37:41 +0200 Subject: [PATCH] [TASK] Mock interfaces instead of abstract classes `getMockForAbstractClass` has been (soft-)deprecated in PHPUnit 10.1: https://github.com/sebastianbergmann/phpunit/issues/5241 Hence, we should replace its usages to follow current best practices. This changes tackles the classes where we can mock an interface instead of an abstract class, allowing us to use `createMock` instead of `getMockForAbstractClass`. Resolves: #101609 Related: #101601 Releases: main, 12.4 Change-Id: I995f70d779a1bc6251bc4479c3dcb2ee548314f1 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80458 Reviewed-by: Christian Kuhn Tested-by: core-ci Tested-by: Christian Kuhn --- .../Tests/Functional/Resource/ResourceStorageTest.php | 4 ++-- .../Tests/Unit/Resource/Driver/DriverRegistryTest.php | 11 +++++------ .../Tests/Unit/Resource/StorageRepositoryTest.php | 6 +++--- .../fluid/Tests/Unit/View/TemplatePathsTest.php | 6 +++--- .../Mvc/Property/PropertyMappingConfigurationTest.php | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php index df3cc0d405e6..4147e3b8dfee 100644 --- a/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php +++ b/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php @@ -18,7 +18,7 @@ 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\DriverInterface; use TYPO3\CMS\Core\Resource\Driver\LocalDriver; use TYPO3\CMS\Core\Resource\File; use TYPO3\CMS\Core\Resource\Folder; @@ -247,7 +247,7 @@ public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteI $this->expectException(\RuntimeException::class); $this->expectExceptionCode(1325952534); $folderMock = $this->createMock(Folder::class); - $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class); + $mockedDriver = $this->createMock(DriverInterface::class); $mockedDriver->expects(self::once())->method('isFolderEmpty')->willReturn(false); $subject = $this->getAccessibleMock(ResourceStorage::class, ['checkFolderActionPermission'], [], '', false); $subject->method('checkFolderActionPermission')->willReturn(true); diff --git a/typo3/sysext/core/Tests/Unit/Resource/Driver/DriverRegistryTest.php b/typo3/sysext/core/Tests/Unit/Resource/Driver/DriverRegistryTest.php index 14903be917ca..33bd8d0d932d 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Driver/DriverRegistryTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Driver/DriverRegistryTest.php @@ -17,7 +17,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver; -use TYPO3\CMS\Core\Resource\Driver\AbstractDriver; use TYPO3\CMS\Core\Resource\Driver\DriverInterface; use TYPO3\CMS\Core\Resource\Driver\DriverRegistry; use TYPO3\CMS\Core\Utility\StringUtility; @@ -30,7 +29,7 @@ final class DriverRegistryTest extends UnitTestCase */ public function registeredDriverClassesCanBeRetrieved(): void { - $className = get_class($this->getMockForAbstractClass(AbstractDriver::class)); + $className = get_class($this->createMock(DriverInterface::class)); $subject = new DriverRegistry(); $subject->registerDriverClass($className, 'foobar'); $returnedClassName = $subject->getDriverClass('foobar'); @@ -55,7 +54,7 @@ public function registerDriverClassThrowsExceptionIfShortnameIsAlreadyTakenByAno { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionCode(1314979451); - $className = get_class($this->getMockForAbstractClass(AbstractDriver::class)); + $className = get_class($this->createMock(DriverInterface::class)); $className2 = get_class($this->getMockForAbstractClass(DriverInterface::class)); $subject = new DriverRegistry(); $subject->registerDriverClass($className, 'foobar'); @@ -78,7 +77,7 @@ public function getDriverClassThrowsExceptionIfClassIsNotRegistered(): void */ public function getDriverClassAcceptsClassNameIfClassIsRegistered(): void { - $className = get_class($this->getMockForAbstractClass(AbstractDriver::class)); + $className = get_class($this->createMock(DriverInterface::class)); $subject = new DriverRegistry(); $subject->registerDriverClass($className, 'foobar'); self::assertEquals($className, $subject->getDriverClass($className)); @@ -89,7 +88,7 @@ public function getDriverClassAcceptsClassNameIfClassIsRegistered(): void */ public function driverRegistryIsInitializedWithPreconfiguredDrivers(): void { - $className = get_class($this->getMockForAbstractClass(AbstractDriver::class)); + $className = get_class($this->createMock(DriverInterface::class)); $shortName = StringUtility::getUniqueId('class_'); $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [ $shortName => [ @@ -105,7 +104,7 @@ public function driverRegistryIsInitializedWithPreconfiguredDrivers(): void */ public function driverExistsReturnsTrueForAllExistingDrivers(): void { - $className = get_class($this->getMockForAbstractClass(AbstractDriver::class)); + $className = get_class($this->createMock(DriverInterface::class)); $shortName = StringUtility::getUniqueId('class_'); $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'] = [ $shortName => [ diff --git a/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php b/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php index cd4e50796e8b..89213457807b 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/StorageRepositoryTest.php @@ -18,7 +18,7 @@ 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\DriverInterface; use TYPO3\CMS\Core\Resource\Driver\DriverRegistry; use TYPO3\CMS\Core\Resource\LocalPath; use TYPO3\CMS\Core\Resource\StorageRepository; @@ -31,7 +31,7 @@ final class StorageRepositoryTest extends UnitTestCase */ public function getDriverObjectAcceptsDriverClassName(): void { - $mockedDriver = $this->getMockForAbstractClass(AbstractDriver::class); + $mockedDriver = $this->createMock(DriverInterface::class); $driverFixtureClass = get_class($mockedDriver); $registry = new DriverRegistry(); $registry->registerDriverClass($driverFixtureClass); @@ -44,7 +44,7 @@ public function getDriverObjectAcceptsDriverClassName(): void ] ); $obj = $subject->_call('getDriverObject', $driverFixtureClass, []); - self::assertInstanceOf(AbstractDriver::class, $obj); + self::assertInstanceOf(DriverInterface::class, $obj); } public static function storageDetectionDataProvider(): array diff --git a/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php b/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php index 511d18a61ff6..30c1b47bad4e 100644 --- a/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php +++ b/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php @@ -102,7 +102,7 @@ public function pathSetterMethodSortsPathsByKeyDescending($method, array $paths, */ public function getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInFrontendMode(): void { - $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass(); + $configurationManager = $this->createMock(ConfigurationManagerInterface::class); $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([ 'plugin.' => [ 'tx_test.' => [ @@ -159,7 +159,7 @@ public function getContextSpecificViewConfigurationSortsTypoScriptConfiguredPath */ public function getContextSpecificViewConfigurationSortsTypoScriptConfiguredPathsCorrectlyInBackendMode(): void { - $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass(); + $configurationManager = $this->createMock(ConfigurationManagerInterface::class); $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([ 'module.' => [ 'tx_test.' => [ @@ -216,7 +216,7 @@ public function getContextSpecificViewConfigurationSortsTypoScriptConfiguredPath */ public function getContextSpecificViewConfigurationDoesNotResolveFromTypoScriptAndDoesNotSortInUnspecifiedMode(): void { - $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass(); + $configurationManager = $this->createMock(ConfigurationManagerInterface::class); $configurationManager->expects(self::once())->method('getConfiguration')->willReturn([ 'plugin.' => [ 'tx_test.' => [ diff --git a/typo3/sysext/form/Tests/Unit/Mvc/Property/PropertyMappingConfigurationTest.php b/typo3/sysext/form/Tests/Unit/Mvc/Property/PropertyMappingConfigurationTest.php index d80aa809617d..77c2d26b808c 100644 --- a/typo3/sysext/form/Tests/Unit/Mvc/Property/PropertyMappingConfigurationTest.php +++ b/typo3/sysext/form/Tests/Unit/Mvc/Property/PropertyMappingConfigurationTest.php @@ -21,8 +21,8 @@ use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration as ExtbasePropertyMappingConfiguration; -use TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator; use TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator; +use TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface; use TYPO3\CMS\Extbase\Validation\ValidatorResolver; use TYPO3\CMS\Form\Domain\Model\FormDefinition; use TYPO3\CMS\Form\Domain\Model\FormElements\FileUpload; @@ -266,7 +266,7 @@ public function afterBuildingFinishedSetsStoragePathToUserUploadIfNeitherSaveToF public function afterBuildingFinishedCopiesValidators(): void { // Some other Validator - $otherValidator = $this->getMockForAbstractClass(AbstractValidator::class); + $otherValidator = $this->createMock(ValidatorInterface::class); // Don't add any validators for now $validators = new \SplObjectStorage();