Skip to content

Commit

Permalink
[TASK] Mock interfaces instead of abstract classes
Browse files Browse the repository at this point in the history
`getMockForAbstractClass` has been (soft-)deprecated in PHPUnit 10.1:
sebastianbergmann/phpunit#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 <[email protected]>
Tested-by: core-ci <[email protected]>
Tested-by: Christian Kuhn <[email protected]>
  • Loading branch information
oliverklee authored and lolli42 committed Aug 8, 2023
1 parent fa77cf8 commit 2bde3f1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Tests/Functional/Resource/ResourceStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions Tests/Unit/Resource/Driver/DriverRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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));
Expand All @@ -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 => [
Expand All @@ -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 => [
Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/Resource/StorageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 2bde3f1

Please sign in to comment.