[TASK] Use real ObjectManager stubs in unit tests 57/59757/3
authorBenjamin Franzke <bfr@qbus.de>
Mon, 18 Feb 2019 07:12:15 +0000 (08:12 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 23 Feb 2019 16:39:30 +0000 (17:39 +0100)
Prevent invocation of the constructor (which instantiates
an internal instance of the extbase container) and do not
mix usage of mocked and stubbed methods.

The mixture happened due to the usage of setMethods():
When specifing `setMethods(['get'])` all methods besides ->get()
are actually proxied to the real ObjectManager methods.

Releases: master, 9.5
Resolves: #87742
Change-Id: I817f8ee90d82f36b8117e873b5802e11f601384e
Reviewed-on: https://review.typo3.org/c/59757
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Tests/Unit/Mvc/Controller/ActionControllerTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php
typo3/sysext/extensionmanager/Tests/Unit/Task/UpdateExtensionListTaskTest.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/ExtensionModelUtilityTest.php
typo3/sysext/form/Tests/Unit/Domain/Configuration/FormDefinitionValidationServiceTest.php

index 07580ec..1e54f3f 100644 (file)
@@ -519,7 +519,7 @@ class ActionControllerTest extends UnitTestCase
      */
     public function rendersAndAssignsAssetsFromViewIntoPageRenderer($viewMock, $expectedHeader, $expectedFooter)
     {
-        $this->mockObjectManager = $this->getMockBuilder(ObjectManager::class)->setMethods(['get'])->getMock();
+        $this->mockObjectManager = $this->createMock(ObjectManager::class);
         $pageRendererMock = $this->getMockBuilder(PageRenderer::class)->setMethods(['addHeaderData', 'addFooterData'])->getMock();
         if (!$viewMock instanceof FluidTemplateView) {
             $this->mockObjectManager->expects($this->never())->method('get');
index 8d3053f..75a51fa 100644 (file)
@@ -118,7 +118,7 @@ class Typo3DbBackendTest extends UnitTestCase
             '',
             false
         );
-        $mockObjectManager = $this->getAccessibleMock(ObjectManager::class, ['get']);
+        $mockObjectManager = $this->createMock(ObjectManager::class);
         $mockObjectManager->expects($this->any())
             ->method('get')
             ->with(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class)
index 1a12131..c0dcbe4 100644 (file)
@@ -48,7 +48,7 @@ class UpdateExtensionListTaskTest extends UnitTestCase
                 ->expects($this->once())
                 ->method('updateExtList');
 
-        $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManager::class)->getMock();
+        $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $objectManagerMock
                 ->expects($this->at(0))
                 ->method('get')
@@ -76,7 +76,7 @@ class UpdateExtensionListTaskTest extends UnitTestCase
     public function executeCallsPersistAllOnPersistenceManager()
     {
         $repositoryHelper = $this->createMock(Helper::class);
-        $objectManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Object\ObjectManager::class)->getMock();
+        $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $objectManagerMock
             ->expects($this->at(0))
             ->method('get')
index 96bf0dc..3d821a2 100644 (file)
@@ -40,7 +40,7 @@ class ExtensionModelUtilityTest extends UnitTestCase
         ]);
         /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
         $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
-        $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
+        $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['dummy']);
         $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
         $dependencyUtility->_set('objectManager', $objectManagerMock);
@@ -62,7 +62,7 @@ class ExtensionModelUtilityTest extends UnitTestCase
         ]);
         /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
         $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
-        $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
+        $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['setIdentifier']);
         $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
         $dependencyUtility->_set('objectManager', $objectManagerMock);
@@ -136,7 +136,7 @@ class ExtensionModelUtilityTest extends UnitTestCase
         $serializedDependencies = serialize($dependencies);
         /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
         $dependencyUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class, ['dummy']);
-        $objectManagerMock = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, ['get']);
+        $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
         $dependencyModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class, ['setHighestVersion', 'setLowestVersion']);
         $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
         $dependencyUtility->_set('objectManager', $objectManagerMock);
index 74348b6..9b65355 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Form\Tests\Unit\Domain\Configuration;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Form\Domain\Configuration\ConfigurationService;
 use TYPO3\CMS\Form\Domain\Configuration\Exception\PropertyException;
 use TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto;
@@ -275,7 +276,9 @@ class FormDefinitionValidationServiceTest extends UnitTestCase
         $formDefinitionValidationService = $this->getAccessibleMock(FormDefinitionValidationService::class, ['getConfigurationService']);
         $formDefinitionValidationService->expects($this->any())->method('getConfigurationService')->willReturn($configurationService);
         GeneralUtility::setSingletonInstance(FormDefinitionValidationService::class, $formDefinitionValidationService);
-        GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService);
+        $objectManager = $this->createMock(ObjectManager::class);
+        $objectManager->expects($this->once())->method('get')->with(ConfigurationService::class)->willReturn($configurationService);
+        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager);
 
         $returnedExceptionCode = -1;
         try {
@@ -329,7 +332,9 @@ class FormDefinitionValidationServiceTest extends UnitTestCase
         $formDefinitionValidationService = $this->getAccessibleMock(FormDefinitionValidationService::class, ['getConfigurationService']);
         $formDefinitionValidationService->expects($this->any())->method('getConfigurationService')->willReturn($configurationService);
         GeneralUtility::setSingletonInstance(FormDefinitionValidationService::class, $formDefinitionValidationService);
-        GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService);
+        $objectManager = $this->createMock(ObjectManager::class);
+        $objectManager->expects($this->once())->method('get')->with(ConfigurationService::class)->willReturn($configurationService);
+        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager);
 
         $returnedExceptionCode = -1;
         try {