From c38e04014126b74f99ec6046dae47f3b201d3009 Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Mon, 2 Dec 2019 10:12:07 +0100 Subject: [PATCH] [TASK] Use inject methods instead of "inject" base test method There are numereous places where reflection is used in our test cases to inject dependencies, however there are methods available doing so, so the tests can be adapted, which will speed up tests. In addition, the $callInaccessibleMethod() function is also replaced by the accessible mock functionality, resulting in faster results than reflection. Resolves: #89824 Releases: master Change-Id: Ia2fc8a8ee4d3b5fc7b0d2de8759a7e5e9ceb7b87 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62503 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Susanne Moog <look@susi.dev> Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Susanne Moog <look@susi.dev> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> --- .../Page/LocalizationControllerTest.php | 16 ++++---- .../Resource/ResourceStorageTest.php | 6 ++- .../Unit/DataHandling/DataHandlerTest.php | 11 ++---- .../Unit/Database/Query/QueryBuilderTest.php | 10 +++-- .../Tests/Unit/Package/PackageManagerTest.php | 2 +- .../Unit/Resource/ResourceStorageTest.php | 38 +++++++++---------- .../Tests/Unit/Mvc/View/JsonViewTest.php | 2 +- .../Tests/Unit/Persistence/RepositoryTest.php | 16 ++++---- .../Unit/Property/PropertyMapperTest.php | 2 +- .../TypeConverter/ObjectConverterTest.php | 6 +-- .../PersistentObjectConverterTest.php | 8 ++-- .../Tests/Unit/Utility/ListUtilityTest.php | 6 +-- .../Widget/AbstractWidgetViewHelperTest.php | 6 +-- .../Core/Widget/WidgetRequestHandlerTest.php | 4 +- .../Tests/Unit/View/TemplatePathsTest.php | 12 +++--- .../ViewHelpers/Be/LinkViewHelperTest.php | 2 +- .../Unit/ViewHelpers/FormViewHelperTest.php | 2 +- .../Unit/ViewHelpers/ImageViewHelperTest.php | 26 +++++-------- .../Finishers/SaveToDatabaseFinisherTest.php | 4 +- .../Typolink/AbstractTypolinkBuilderTest.php | 8 +--- .../SilentConfigurationUpgradeServiceTest.php | 6 ++- 21 files changed, 91 insertions(+), 102 deletions(-) diff --git a/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php b/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php index 51947910eb8c..c5fc6a4283c5 100644 --- a/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php +++ b/typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php @@ -59,9 +59,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase $this->setUpFrontendRootPage(1); $this->setUpFrontendSite(1, $this->siteLanguageConfiguration); - $this->subject = $this->getMockBuilder(LocalizationController::class) - ->setMethods(['getPageColumns']) - ->getMock(); + $this->subject = $this->getAccessibleMock(LocalizationController::class, ['getPageColumns']); } /** @@ -77,7 +75,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase 'uidList' => [1, 2, 3], 'action' => LocalizationController::ACTION_LOCALIZE, ]; - $this->callInaccessibleMethod($this->subject, 'process', $params); + $this->subject->_call('process', $params); $this->assertAssertionDataSet('TranslatedFromDefault'); } @@ -95,7 +93,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase 'uidList' => [4, 5, 6], // uids of tt_content-danish-language 'action' => LocalizationController::ACTION_LOCALIZE, ]; - $this->callInaccessibleMethod($this->subject, 'process', $params); + $this->subject->_call('process', $params); $this->assertAssertionDataSet('TranslatedFromTranslation'); } @@ -111,7 +109,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase 'uidList' => [1, 2, 3], 'action' => LocalizationController::ACTION_COPY, ]; - $this->callInaccessibleMethod($this->subject, 'process', $params); + $this->subject->_call('process', $params); $this->assertAssertionDataSet('CopiedFromDefault'); } @@ -129,7 +127,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase 'uidList' => [4, 5, 6], // uids of tt_content-danish-language 'action' => LocalizationController::ACTION_COPY, ]; - $this->callInaccessibleMethod($this->subject, 'process', $params); + $this->subject->_call('process', $params); $this->assertAssertionDataSet('CopiedFromTranslation'); } @@ -154,7 +152,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase 'uidList' => [1, 2, 3], 'action' => LocalizationController::ACTION_COPY, ]; - $this->callInaccessibleMethod($this->subject, 'process', $params); + $this->subject->_call('process', $params); // Create another content element in default language $data = [ @@ -181,7 +179,7 @@ class LocalizationControllerTest extends AbstractDataHandlerActionTestCase 'uidList' => [$newContentElementUid], 'action' => LocalizationController::ACTION_COPY, ]; - $this->callInaccessibleMethod($this->subject, 'process', $params); + $this->subject->_call('process', $params); $this->assertAssertionDataSet('CreatedElementOrdering'); } diff --git a/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php index cc4daa109b1d..97f2d1ccfb88 100644 --- a/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php +++ b/typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php @@ -413,7 +413,11 @@ class ResourceStorageTest extends FunctionalTestCase self::assertSame($expectedFiles, iterator_to_array($result)); // Check if search also works for non hierarchical storages/drivers - $this->inject($subject, 'capabilities', $subject->getCapabilities() & 7); + // This is a hack, as capabilities is not settable from the outside + $objectReflection = new \ReflectionObject($subject); + $property = $objectReflection->getProperty('capabilities'); + $property->setAccessible(true); + $property->setValue('capabilities', $subject->getCapabilities() & 7); $result = $subject->searchFiles($search, $folder); $expectedFiles = array_map([$subject, 'getFile'], $expectedIdentifiers); self::assertSame($expectedFiles, iterator_to_array($result)); diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php index de514255bdcc..cac1305c61aa 100644 --- a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php +++ b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php @@ -583,14 +583,9 @@ class DataHandlerTest extends UnitTestCase */ public function equalSubmittedAndStoredValuesAreDetermined($expected, $submittedValue, $storedValue, $storedType, $allowNull) { - $result = $this->callInaccessibleMethod( - $this->subject, - 'isSubmittedValueEqualToStoredValue', - $submittedValue, - $storedValue, - $storedType, - $allowNull - ); + $result = \Closure::bind(function () use ($submittedValue, $storedValue, $storedType, $allowNull) { + return $this->isSubmittedValueEqualToStoredValue($submittedValue, $storedValue, $storedType, $allowNull); + }, $this->subject, DataHandler::class)(); self::assertEquals($expected, $result); } diff --git a/typo3/sysext/core/Tests/Unit/Database/Query/QueryBuilderTest.php b/typo3/sysext/core/Tests/Unit/Database/Query/QueryBuilderTest.php index 5ef57a3d2903..6e6a1b080a65 100644 --- a/typo3/sysext/core/Tests/Unit/Database/Query/QueryBuilderTest.php +++ b/typo3/sysext/core/Tests/Unit/Database/Query/QueryBuilderTest.php @@ -1138,7 +1138,11 @@ class QueryBuilderTest extends UnitTestCase ] ] ]); - $result = $this->callInaccessibleMethod($this->subject, 'getQueriedTables'); + + // Call a protected method + $result = \Closure::bind(function () { + return $this->getQueriedTables(); + }, $this->subject, QueryBuilder::class)(); $expected = [ 'aTable' => 'aTable', @@ -1194,8 +1198,8 @@ class QueryBuilderTest extends UnitTestCase $databasePlatformProphecy = $this->prophesize($platform); $databasePlatformProphecy->getIdentifierQuoteCharacter()->willReturn($quoteChar); $connectionProphecy->getDatabasePlatform()->willReturn($databasePlatformProphecy); - $subject = GeneralUtility::makeInstance(QueryBuilder::class, $connectionProphecy->reveal()); - $result = $this->callInaccessibleMethod($subject, 'unquoteSingleIdentifier', $input); + $subject = $this->getAccessibleMock(QueryBuilder::class, ['dummy'], [$connectionProphecy->reveal()]); + $result = $subject->_call('unquoteSingleIdentifier', $input); self::assertEquals($expected, $result); } diff --git a/typo3/sysext/core/Tests/Unit/Package/PackageManagerTest.php b/typo3/sysext/core/Tests/Unit/Package/PackageManagerTest.php index 7341150ee1eb..89999bd0fea6 100644 --- a/typo3/sysext/core/Tests/Unit/Package/PackageManagerTest.php +++ b/typo3/sysext/core/Tests/Unit/Package/PackageManagerTest.php @@ -70,7 +70,7 @@ class PackageManagerTest extends UnitTestCase ]; $this->packageManager->injectCoreCache($mockCache); - $this->inject($this->packageManager, 'composerNameToPackageKeyMap', $composerNameToPackageKeyMap); + $this->packageManager->_set('composerNameToPackageKeyMap', $composerNameToPackageKeyMap); $this->packageManager->_set('packagesBasePath', 'vfs://Test/Packages/'); $this->packageManager->_set('packageStatesPathAndFilename', 'vfs://Test/Configuration/PackageStates.php'); } diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php index 21094b9f8955..8e14037cadc2 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php @@ -481,24 +481,23 @@ class ResourceStorageTest extends BaseTestCase public function metaDataEditIsAllowedWhenWhenInFileMount(): void { $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false); - $this->prepareSubject([], false, $driverMock, null, [], ['isWithinProcessingFolder']); + $resourceFactory = $this->prophesize(ResourceFactory::class); + $this->prepareSubject([], false, $driverMock, $resourceFactory->reveal(), [], ['isWithinProcessingFolder']); - $fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject); $folderStub = new Folder($this->subject, '/foo/', 'foo'); + $resourceFactory->createFolderObject(Argument::cetera())->willReturn($folderStub); + $fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject); $driverMock->expects(self::once()) ->method('isWithin') ->with($folderStub->getIdentifier(), $fileStub->getIdentifier()) ->willReturn(true); $this->subject->setEvaluatePermissions(true); - $fileMounts = [ - '/foo/' => [ - 'path' => '/foo/', - 'title' => 'Foo', - 'folder' => $folderStub, - ] - ]; - $this->inject($this->subject, 'fileMounts', $fileMounts); + $this->subject->addFileMount('/foo/', [ + 'path' => '/foo/', + 'title' => 'Foo', + 'folder' => $folderStub, + ]); self::assertTrue($this->subject->checkFileActionPermission('editMeta', $fileStub)); } @@ -508,25 +507,24 @@ class ResourceStorageTest extends BaseTestCase public function metaDataEditIsNotAllowedWhenWhenInReadOnlyFileMount(): void { $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false); - $this->prepareSubject([], false, $driverMock, null, [], ['isWithinProcessingFolder']); + $resourceFactory = $this->prophesize(ResourceFactory::class); + $this->prepareSubject([], false, $driverMock, $resourceFactory->reveal(), [], ['isWithinProcessingFolder']); $fileStub = new File(['identifier' => '/foo/bar.jpg'], $this->subject); $folderStub = new Folder($this->subject, '/foo/', 'foo'); + $resourceFactory->createFolderObject(Argument::cetera())->willReturn($folderStub); $driverMock->expects(self::once()) ->method('isWithin') ->with($folderStub->getIdentifier(), $fileStub->getIdentifier()) ->willReturn(true); $this->subject->setEvaluatePermissions(true); - $fileMounts = [ - '/foo/' => [ - 'path' => '/foo/', - 'title' => 'Foo', - 'folder' => $folderStub, - 'read_only' => true, - ] - ]; - $this->inject($this->subject, 'fileMounts', $fileMounts); + $this->subject->addFileMount('/foo/', [ + 'path' => '/foo/', + 'title' => 'Foo', + 'folder' => $folderStub, + 'read_only' => true, + ]); self::assertFalse($this->subject->checkFileActionPermission('editMeta', $fileStub)); } diff --git a/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php b/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php index 5e499225a2d2..2cc5d7b23dce 100644 --- a/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php @@ -316,7 +316,7 @@ class JsonViewTest extends UnitTestCase }); $jsonView = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\View\JsonView::class, ['dummy'], [], '', false); - $this->inject($jsonView, 'reflectionService', $reflectionService); + $jsonView->injectReflectionService($reflectionService); $actual = $jsonView->_call('transformValue', $object, $configuration); self::assertSame($expected, $actual); } diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php index 7f9e076f3546..06a68d8f5c4f 100644 --- a/typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php @@ -81,7 +81,7 @@ class RepositoryTest extends UnitTestCase $this->mockSession = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Session::class); $this->mockConfigurationManager = $this->createMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class); $this->mockBackend = $this->getAccessibleMock(Backend::class, ['dummy'], [$this->mockConfigurationManager], '', false); - $this->inject($this->mockBackend, 'session', $this->mockSession); + $this->mockBackend->_set('session', $this->mockSession); $this->mockPersistenceManager = $this->getAccessibleMock( \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class, ['createQueryForType'], @@ -91,11 +91,11 @@ class RepositoryTest extends UnitTestCase $this->mockSession ] ); - $this->inject($this->mockBackend, 'persistenceManager', $this->mockPersistenceManager); + $this->mockBackend->setPersistenceManager($this->mockPersistenceManager); $this->mockPersistenceManager->expects(self::any())->method('createQueryForType')->willReturn($this->mockQuery); $this->mockObjectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class); $this->repository = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Repository::class, ['dummy'], [$this->mockObjectManager]); - $this->repository->_set('persistenceManager', $this->mockPersistenceManager); + $this->repository->injectPersistenceManager($this->mockPersistenceManager); } /** @@ -115,7 +115,7 @@ class RepositoryTest extends UnitTestCase $mockPersistenceManager->expects(self::once())->method('createQueryForType')->with('ExpectedType'); $this->repository->_set('objectType', 'ExpectedType'); - $this->inject($this->repository, 'persistenceManager', $mockPersistenceManager); + $this->repository->injectPersistenceManager($mockPersistenceManager); $this->repository->createQuery(); } @@ -132,7 +132,7 @@ class RepositoryTest extends UnitTestCase $mockPersistenceManager->expects(self::exactly(2))->method('createQueryForType')->with('ExpectedType')->willReturn($mockQuery); $this->repository->_set('objectType', 'ExpectedType'); - $this->inject($this->repository, 'persistenceManager', $mockPersistenceManager); + $this->repository->injectPersistenceManager($mockPersistenceManager); $this->repository->setDefaultOrderings($orderings); $this->repository->createQuery(); @@ -187,7 +187,7 @@ class RepositoryTest extends UnitTestCase $object = new \stdClass(); $mockPersistenceManager = $this->createMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class); $mockPersistenceManager->expects(self::once())->method('add')->with($object); - $this->inject($this->repository, 'persistenceManager', $mockPersistenceManager); + $this->repository->injectPersistenceManager($mockPersistenceManager); $this->repository->_set('objectType', get_class($object)); $this->repository->add($object); } @@ -200,7 +200,7 @@ class RepositoryTest extends UnitTestCase $object = new \stdClass(); $mockPersistenceManager = $this->createMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class); $mockPersistenceManager->expects(self::once())->method('remove')->with($object); - $this->inject($this->repository, 'persistenceManager', $mockPersistenceManager); + $this->repository->injectPersistenceManager($mockPersistenceManager); $this->repository->_set('objectType', get_class($object)); $this->repository->remove($object); } @@ -213,7 +213,7 @@ class RepositoryTest extends UnitTestCase $object = new \stdClass(); $mockPersistenceManager = $this->createMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class); $mockPersistenceManager->expects(self::once())->method('update')->with($object); - $this->inject($this->repository, 'persistenceManager', $mockPersistenceManager); + $this->repository->injectPersistenceManager($mockPersistenceManager); $this->repository->_set('objectType', get_class($object)); $this->repository->update($object); } diff --git a/typo3/sysext/extbase/Tests/Unit/Property/PropertyMapperTest.php b/typo3/sysext/extbase/Tests/Unit/Property/PropertyMapperTest.php index bde1d75c2f30..2b82be06d127 100644 --- a/typo3/sysext/extbase/Tests/Unit/Property/PropertyMapperTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Property/PropertyMapperTest.php @@ -341,7 +341,7 @@ class PropertyMapperTest extends UnitTestCase public function convertShouldAskConfigurationBuilderForDefaultConfiguration() { $propertyMapper = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Property\PropertyMapper::class, ['dummy']); - $this->inject($propertyMapper, 'configurationBuilder', $this->mockConfigurationBuilder); + $propertyMapper->injectConfigurationBuilder($this->mockConfigurationBuilder); $this->mockConfigurationBuilder->expects(self::once())->method('build')->willReturn($this->mockConfiguration); diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/ObjectConverterTest.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/ObjectConverterTest.php index b93550536dcd..c035c252face 100644 --- a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/ObjectConverterTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/ObjectConverterTest.php @@ -56,9 +56,9 @@ class ObjectConverterTest extends UnitTestCase $this->mockContainer = $this->createMock(\TYPO3\CMS\Extbase\Object\Container\Container::class); $this->converter = new ObjectConverter(); - $this->inject($this->converter, 'reflectionService', $this->mockReflectionService); - $this->inject($this->converter, 'objectManager', $this->mockObjectManager); - $this->inject($this->converter, 'objectContainer', $this->mockContainer); + $this->converter->injectReflectionService($this->mockReflectionService); + $this->converter->injectObjectManager($this->mockObjectManager); + $this->converter->injectObjectContainer($this->mockContainer); } /** diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php index 2b307c4574d9..42ad627d1128 100644 --- a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php @@ -65,10 +65,10 @@ class PersistentObjectConverterTest extends UnitTestCase parent::setUp(); $this->converter = new PersistentObjectConverter(); $this->mockReflectionService = $this->createMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class); - $this->inject($this->converter, 'reflectionService', $this->mockReflectionService); + $this->converter->injectReflectionService($this->mockReflectionService); $this->mockPersistenceManager = $this->createMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class); - $this->inject($this->converter, 'persistenceManager', $this->mockPersistenceManager); + $this->converter->injectPersistenceManager($this->mockPersistenceManager); $this->mockObjectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class); $this->mockObjectManager->expects(self::any()) @@ -80,10 +80,10 @@ class PersistentObjectConverterTest extends UnitTestCase } return $reflectionClass->newInstanceArgs($arguments); }); - $this->inject($this->converter, 'objectManager', $this->mockObjectManager); + $this->converter->injectObjectManager($this->mockObjectManager); $this->mockContainer = $this->createMock(\TYPO3\CMS\Extbase\Object\Container\Container::class); - $this->inject($this->converter, 'objectContainer', $this->mockContainer); + $this->converter->injectObjectContainer($this->mockContainer); } /** diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Utility/ListUtilityTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Utility/ListUtilityTest.php index 700aef5e9d22..a1e138c8d2a4 100644 --- a/typo3/sysext/extensionmanager/Tests/Unit/Utility/ListUtilityTest.php +++ b/typo3/sysext/extensionmanager/Tests/Unit/Utility/ListUtilityTest.php @@ -49,7 +49,7 @@ class ListUtilityTest extends UnitTestCase 'news' => $this->getMockBuilder(Package::class)->disableOriginalConstructor()->getMock(), 'saltedpasswords' => $this->getMockBuilder(Package::class)->disableOriginalConstructor()->getMock(), ]); - $this->inject($this->subject, 'packageManager', $packageManagerMock); + $this->subject->injectPackageManager($packageManagerMock); } /** @@ -159,10 +159,10 @@ class ListUtilityTest extends UnitTestCase */ public function enrichExtensionsWithEmConfInformation($extensions, $emConf, $expectedResult) { - $this->inject($this->subject, 'extensionRepository', $this->getAccessibleMock(ExtensionRepository::class, ['findOneByExtensionKeyAndVersion', 'findHighestAvailableVersion'], [], '', false)); + $this->subject->injectExtensionRepository($this->getAccessibleMock(ExtensionRepository::class, ['findOneByExtensionKeyAndVersion', 'findHighestAvailableVersion'], [], '', false)); $emConfUtilityMock = $this->getMockBuilder(EmConfUtility::class)->getMock(); $emConfUtilityMock->expects(self::any())->method('includeEmConf')->willReturn($emConf); - $this->inject($this->subject, 'emConfUtility', $emConfUtilityMock); + $this->subject->injectEmConfUtility($emConfUtilityMock); self::assertEquals($expectedResult, $this->subject->enrichExtensionsWithEmConfAndTerInformation($extensions)); } } diff --git a/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetViewHelperTest.php index 674459c9d4bf..4e69f282f480 100644 --- a/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/Core/Widget/AbstractWidgetViewHelperTest.php @@ -232,11 +232,9 @@ class AbstractWidgetViewHelperTest extends UnitTestCase */ public function getWidgetConfigurationReturnsArgumentsProperty() { - $viewHelper = $this->getMockBuilder(AbstractWidgetViewHelper::class) - ->setMethods(['dummy']) - ->getMock(); + $viewHelper = $this->getAccessibleMock(AbstractWidgetViewHelper::class, ['dummy'], [], '', false); $viewHelper->setArguments(['foo' => 'bar']); - self::assertEquals(['foo' => 'bar'], $this->callInaccessibleMethod($viewHelper, 'getWidgetConfiguration')); + self::assertEquals(['foo' => 'bar'], $viewHelper->_call('getWidgetConfiguration')); } /** diff --git a/typo3/sysext/fluid/Tests/Unit/Core/Widget/WidgetRequestHandlerTest.php b/typo3/sysext/fluid/Tests/Unit/Core/Widget/WidgetRequestHandlerTest.php index 012a59053cdd..83dd25d6fef6 100644 --- a/typo3/sysext/fluid/Tests/Unit/Core/Widget/WidgetRequestHandlerTest.php +++ b/typo3/sysext/fluid/Tests/Unit/Core/Widget/WidgetRequestHandlerTest.php @@ -90,8 +90,8 @@ class WidgetRequestHandlerTest extends UnitTestCase ->disableOriginalConstructor() ->getMock(); $requestDispatcher->expects(self::once())->method('dispatch')->with($request); - $this->inject($handler, 'widgetRequestBuilder', $requestBuilder); - $this->inject($handler, 'dispatcher', $requestDispatcher); + $handler->injectWidgetRequestBuilder($requestBuilder); + $handler->injectDispatcher($requestDispatcher); $handler->handleRequest(); } } diff --git a/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php b/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php index 145555fc7567..0b8d3dcbc201 100644 --- a/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php +++ b/typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php @@ -131,12 +131,12 @@ class TemplatePathsTest extends UnitTestCase ] ] ]); - $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock(); + $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode']); $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/'); $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager); $subject->expects(self::once())->method('isBackendMode')->willReturn(false); $subject->expects(self::once())->method('isFrontendMode')->willReturn(true); - $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test'); + $result = $subject->_call('getContextSpecificViewConfiguration', 'test'); self::assertSame([ 'templateRootPaths' => [ 'test/Templates/', @@ -188,12 +188,12 @@ class TemplatePathsTest extends UnitTestCase ] ] ]); - $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock(); + $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode']); $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/'); $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager); $subject->expects(self::once())->method('isBackendMode')->willReturn(true); $subject->expects(self::never())->method('isFrontendMode'); - $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test'); + $result = $subject->_call('getContextSpecificViewConfiguration', 'test'); self::assertSame([ 'templateRootPaths' => [ 'test/Templates/', @@ -245,12 +245,12 @@ class TemplatePathsTest extends UnitTestCase ] ] ]); - $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock(); + $subject = $this->getAccessibleMock(TemplatePaths::class, ['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode']); $subject->expects(self::once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/'); $subject->expects(self::once())->method('getConfigurationManager')->willReturn($configurationManager); $subject->expects(self::once())->method('isBackendMode')->willReturn(false); $subject->expects(self::once())->method('isFrontendMode')->willReturn(false); - $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test'); + $result = $subject->_call('getContextSpecificViewConfiguration', 'test'); self::assertSame([ 'templateRootPaths' => [ 'test/Templates/' diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Be/LinkViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Be/LinkViewHelperTest.php index b1a99ebd6164..5f5edf343228 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Be/LinkViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Be/LinkViewHelperTest.php @@ -57,7 +57,7 @@ class LinkViewHelperTest extends ViewHelperBaseTestcase 'render' ])->getMock(); - $this->inject($this->viewHelper, 'tag', $this->tagBuilder); + $this->viewHelper->setTagBuilder($this->tagBuilder); } /** diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/FormViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/FormViewHelperTest.php index 9b6917c52137..13a77a4abc1c 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/FormViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/FormViewHelperTest.php @@ -106,7 +106,7 @@ class FormViewHelperTest extends ViewHelperBaseTestcase $tagBuilder->expects(self::once())->method('addAttribute')->with('action', 'foobar'); $viewHelper->_set('tag', $tagBuilder); $viewHelper->setArguments(['actionUri' => 'foobar']); - $this->callInaccessibleMethod($viewHelper, 'setFormActionUri'); + $viewHelper->_call('setFormActionUri'); } /** diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ImageViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ImageViewHelperTest.php index af3705257cee..5666fef075ab 100644 --- a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ImageViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/ImageViewHelperTest.php @@ -129,10 +129,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase { $this->setArgumentsUnderTest($this->viewHelper, $arguments); - $image = $this->getMockBuilder(FileReference::class) - ->setMethods(['getProperty', 'hasProperty']) - ->disableOriginalConstructor() - ->getMock(); + $image = $this->getAccessibleMock(FileReference::class, ['getProperty', 'hasProperty'], [], '', false); $image->expects(self::any())->method('hasProperty')->willReturn(true); $image->expects(self::any())->method('getProperty')->willReturnMap([ ['width', $arguments['width']], @@ -155,14 +152,14 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase ['height', $arguments['height']], ]); - $this->inject($image, 'originalFile', $originalFile); - $this->inject($image, 'propertiesOfFileReference', []); + $image->_set('originalFile', $originalFile); + $image->_set('propertiesOfFileReference', []); $imageService = $this->createMock(ImageService::class); $imageService->expects(self::once())->method('getImage')->willReturn($image); $imageService->expects(self::once())->method('applyProcessingInstructions')->with($image, self::anything())->willReturn($processedFile); $imageService->expects(self::once())->method('getImageUri')->with($processedFile)->willReturn('test.png'); - $this->inject($this->viewHelper, 'imageService', $imageService); + $this->viewHelper->injectImageService($imageService); $tagBuilder = $this->getMockBuilder(TagBuilder::class) ->setMethods(['addAttribute', 'render']) @@ -172,7 +169,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase $tagBuilder->expects(self::at(++ $index))->method('addAttribute')->with($expectedAttribute, $expectedValue); } $tagBuilder->expects(self::once())->method('render'); - $this->inject($this->viewHelper, 'tag', $tagBuilder); + $this->viewHelper->setTagBuilder($tagBuilder); $this->viewHelper->render(); } @@ -232,10 +229,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase { $this->setArgumentsUnderTest($this->viewHelper, $arguments); - $image = $this->getMockBuilder(FileReference::class) - ->setMethods(['getProperty', 'hasProperty']) - ->disableOriginalConstructor() - ->getMock(); + $image = $this->getAccessibleMock(FileReference::class, ['getProperty', 'hasProperty'], [], '', false); $image->expects(self::any())->method('hasProperty')->willReturn(false); $e = new \InvalidArgumentException('', 1556282257); @@ -255,14 +249,14 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase ['height', $arguments['height']], ]); - $this->inject($image, 'originalFile', $originalFile); - $this->inject($image, 'propertiesOfFileReference', []); + $image->_set('originalFile', $originalFile); + $image->_set('propertiesOfFileReference', []); $imageService = $this->createMock(ImageService::class); $imageService->expects(self::once())->method('getImage')->willReturn($image); $imageService->expects(self::once())->method('applyProcessingInstructions')->with($image, self::anything())->willReturn($processedFile); $imageService->expects(self::once())->method('getImageUri')->with($processedFile)->willReturn('test.png'); - $this->inject($this->viewHelper, 'imageService', $imageService); + $this->viewHelper->injectImageService($imageService); $tagBuilder = $this->getMockBuilder(TagBuilder::class) ->setMethods(['addAttribute', 'render']) @@ -272,7 +266,7 @@ class ImageViewHelperTest extends ViewHelperBaseTestcase $tagBuilder->expects(self::at(++ $index))->method('addAttribute')->with($expectedAttribute, $expectedValue); } $tagBuilder->expects(self::once())->method('render'); - $this->inject($this->viewHelper, 'tag', $tagBuilder); + $this->viewHelper->setTagBuilder($tagBuilder); $this->viewHelper->render(); } diff --git a/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php b/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php index ba8d6b9c496c..65c4204ab920 100644 --- a/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php +++ b/typo3/sysext/form/Tests/Unit/Domain/Finishers/SaveToDatabaseFinisherTest.php @@ -78,7 +78,7 @@ class SaveToDatabaseFinisherTest extends UnitTestCase $saveToDatabaseFinisher = $this->getMockBuilder(SaveToDatabaseFinisher::class) ->setMethods(['process']) ->getMock(); - $this->inject($saveToDatabaseFinisher, 'options', [ + $saveToDatabaseFinisher->setOptions([ 'table' => 'tx_foo', 'databaseColumnMappings' => [ 'foo' => 1, @@ -156,7 +156,7 @@ class SaveToDatabaseFinisherTest extends UnitTestCase $saveToDatabaseFinisher = $this->getMockBuilder(SaveToDatabaseFinisher::class) ->setMethods(['process']) ->getMock(); - $this->inject($saveToDatabaseFinisher, 'options', [ + $saveToDatabaseFinisher->setOptions([ [ 'table' => 'tx_foo', 'databaseColumnMappings' => [ diff --git a/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php b/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php index 32ad0cde0b1c..6c0161868768 100644 --- a/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Typolink/AbstractTypolinkBuilderTest.php @@ -340,12 +340,8 @@ class AbstractTypolinkBuilderTest extends UnitTestCase $this->frontendControllerMock->config = ['config' => [ 'doctype' => $doctype]]; $renderer = GeneralUtility::makeInstance(ContentObjectRenderer::class); - $subject = $this->getMockBuilder(AbstractTypolinkBuilder::class) - ->setConstructorArgs([$renderer, $this->frontendControllerMock]) - ->setMethods(['build']) - ->getMock(); - $actual = $this->callInaccessibleMethod( - $subject, + $subject = $this->getAccessibleMockForAbstractClass(AbstractTypolinkBuilder::class, [$renderer, $this->frontendControllerMock]); + $actual = $subject->_call( 'resolveTargetAttribute', $conf, $name, diff --git a/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php b/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php index c545eb3506ae..8899f18f2a27 100644 --- a/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php +++ b/typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php @@ -706,8 +706,10 @@ class SilentConfigurationUpgradeServiceTest extends UnitTestCase $this->expectException(ConfigurationChangedException::class); $silentConfigurationUpgradeService = new SilentConfigurationUpgradeService($configurationManager->reveal()); - - $this->callInaccessibleMethod($silentConfigurationUpgradeService, 'setImageMagickDetailSettings'); + // Call protected method + \Closure::bind(function () { + return $this->setImageMagickDetailSettings(); + }, $silentConfigurationUpgradeService, SilentConfigurationUpgradeService::class)(); } /** -- GitLab