[BUGFIX] Tests: Improve Mocking in ext:extbase 07/28207/3
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Sun, 9 Mar 2014 23:39:10 +0000 (00:39 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 10 Mar 2014 00:08:44 +0000 (01:08 +0100)
Change-Id: I61f7f92da42d691b0556f1e53b20d39eb082c12f
Resolves: #56700
Related: #51436
Releases: 6.2
Reviewed-on: https://review.typo3.org/28207
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Tests/Unit/Core/BootstrapTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php

index 4f0b138..11e587e 100644 (file)
@@ -90,7 +90,10 @@ class BootstrapTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $cliRequestHandler->expects($this->any())->method('canHandleRequest')->will($this->returnValue(TRUE));
                $cliRequestHandler->_set('objectManager', $this->objectManager);
                $cliRequestHandler->_set('requestBuilder', $this->objectManager->get('TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder'));
-               $cliRequestHandler->_set('dispatcher', $this->objectManager->get('TYPO3\CMS\Extbase\Mvc\Dispatcher'));
+
+               /** @var \TYPO3\CMS\Extbase\Mvc\Dispatcher|\PHPUnit_Framework_MockObject_MockObject $mockDispatcher */
+               $mockDispatcher = $this->getMock('TYPO3\CMS\Extbase\Mvc\Dispatcher', array('dispatch'), array(), '', FALSE);
+               $cliRequestHandler->_set('dispatcher', $mockDispatcher);
                /** @var $cliResponse \TYPO3\CMS\Extbase\Mvc\Cli\Response */
                $cliResponse = $this->getMock('TYPO3\CMS\Extbase\Mvc\Cli\Response', array('send'));
 
@@ -98,7 +101,7 @@ class BootstrapTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $reflectionServiceMock = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
 
                /** @var $bootstrap \TYPO3\CMS\Extbase\Core\Bootstrap |\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
-               $bootstrap = $this->getAccessibleMock('TYPO3\CMS\Extbase\Core\Bootstrap', array('isInCliMode', 'initializeReflection'));
+               $bootstrap = $this->getAccessibleMock('TYPO3\CMS\Extbase\Core\Bootstrap', array('isInCliMode', 'initializeReflection', 'configureObjectManager'));
                $bootstrap->_set('reflectionService', $reflectionServiceMock);
                $bootstrap->expects($this->once())->method('isInCliMode')->will($this->returnValue(TRUE));
 
index 0c22fe9..27ef1a5 100644 (file)
@@ -67,11 +67,8 @@ class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $GLOBALS['TCA'][$table]['ctrl'] = array(
                        'languageField' => 'sys_language_uid'
                );
-               $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
-               $tsfe->sys_language_content = 0;
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->initializeObject();
-               $GLOBALS['TSFE'] = $tsfe;
+               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings|\PHPUnit_Framework_MockObject_MockObject $querySettings */
+               $querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
                $sql = array();
                $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
                $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
@@ -82,39 +79,19 @@ class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
-       public function addSysLanguageStatementWorksForNonDefaultLanguageInFrontend() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid'
-               );
-               $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
-               $tsfe->sys_language_content = 1;
-               $GLOBALS['TSFE'] = $tsfe;
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->initializeObject();
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForNonDefaultLanguageInBackend() {
+       public function addSysLanguageStatementWorksForNonDefaultLanguage() {
                $table = uniqid('tx_coretest_table');
                $GLOBALS['TCA'][$table]['ctrl'] = array(
                        'languageField' => 'sys_language_uid'
                );
-               $_GET['L'] = 1;
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->initializeObject();
                $sql = array();
+               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings|\PHPUnit_Framework_MockObject_MockObject $querySettings */
+               $querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'));
+               $querySettings->setLanguageUid('1');
                $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
                $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
-               $this->assertSame($expectedSql, $sql);
+               $result = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
+               $this->assertSame($result, $sql);
        }
 
        /**