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/+/80455
Tested-by: core-ci <[email protected]>
Tested-by: Christian Kuhn <[email protected]>
Reviewed-by: Christian Kuhn <[email protected]>
Reviewed-by: Stefan B�rk <[email protected]>
Tested-by: Stefan B�rk <[email protected]>
  • Loading branch information
oliverklee authored and lolli42 committed Aug 8, 2023
1 parent 7a10cea commit 898728e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
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
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
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
6 changes: 3 additions & 3 deletions typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.' => [
Expand Down Expand Up @@ -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.' => [
Expand Down Expand Up @@ -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.' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 898728e

Please sign in to comment.