From 2bde3f16befd1b1ebebcf5e483042747789f6377 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 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Tests/Functional/Resource/ResourceStorageTest.php b/Tests/Functional/Resource/ResourceStorageTest.php index df3cc0d405..4147e3b8df 100644 --- a/Tests/Functional/Resource/ResourceStorageTest.php +++ b/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/Tests/Unit/Resource/Driver/DriverRegistryTest.php b/Tests/Unit/Resource/Driver/DriverRegistryTest.php index 14903be917..33bd8d0d93 100644 --- a/Tests/Unit/Resource/Driver/DriverRegistryTest.php +++ b/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/Tests/Unit/Resource/StorageRepositoryTest.php b/Tests/Unit/Resource/StorageRepositoryTest.php index cd4e50796e..8921345780 100644 --- a/Tests/Unit/Resource/StorageRepositoryTest.php +++ b/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