[BUGFIX] PHP 5.4 unit test warnings
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 1 Nov 2012 23:33:25 +0000 (00:33 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 1 Nov 2012 23:47:11 +0000 (00:47 +0100)
PHP 5.4 throws warnings "Creating default object from empty value"
if $foo->bar is accessed and $foo is not an object. This is the
case in several unit tests, especially if $GLOBALS['TSFE'] is accessed.
The patch fixes those warnings by initializing the object in question
with an instance of stdClass.
Furtermore some dumplicate cleanups of global backup handling is
removed that is already done in the parent classes.

Change-Id: I4c060632783926d76ff96b2eadf3c2ae89f6ae4e
Fixes: #42610
Releases: 6.0
Reviewed-on: http://review.typo3.org/16116
Reviewed-by: Helmut Hummel
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/FrontendConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Storage/Typo3DbBackendTest.php
typo3/sysext/extbase/Tests/Unit/Service/ExtensionServiceTest.php
typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php

index 2bfe015..79f1190 100644 (file)
@@ -29,13 +29,6 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Configuration;
 class BackendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * Enable backup of global and system variables
-        *
-        * @var boolean
-        */
-       protected $backupGlobals = TRUE;
-
-       /**
         * @var \TYPO3\CMS\Core\Database\DatabaseConnection
         */
        protected $typo3DbBackup;
index 6a537c7..8c7434a 100644 (file)
@@ -29,11 +29,6 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Configuration;
 class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
-        */
-       protected $tsfeBackup;
-
-       /**
         * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
         */
        protected $mockContentObject;
@@ -44,11 +39,6 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
        protected $frontendConfigurationManager;
 
        /**
-        * @var array
-        */
-       protected $extConfBackup;
-
-       /**
         * @var \TYPO3\CMS\Extbase\Service\TypoScriptService|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
         */
        protected $mockTypoScriptService;
@@ -57,9 +47,9 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
         * Sets up this testcase
         */
        public function setUp() {
-               $this->tsfeBackup = $GLOBALS['TSFE'];
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->tmpl = new \stdClass();
                $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
-               $this->extConfBackup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'];
                $this->frontendConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('dummy'));
                $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
                $this->mockTypoScriptService = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService');
@@ -67,14 +57,6 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
        }
 
        /**
-        * Tears down this testcase
-        */
-       public function tearDown() {
-               $GLOBALS['TSFE']->tmpl->setup;
-               $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = $this->extConfBackup;
-       }
-
-       /**
         * @test
         */
        public function getTypoScriptSetupReturnsSetupFromTsfe() {
index 97d0094..f208db5 100644 (file)
@@ -29,13 +29,6 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Storage;
 class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * Enable backup of global and system variables
-        *
-        * @var boolean
-        */
-       protected $backupGlobals = true;
-
-       /**
         * This is the data provider for the statement generation with a basic comparison
         *
         * @return array An array of data
@@ -292,6 +285,7 @@ class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                        ),
                        'delete' => 'deleted_column'
                );
+               $GLOBALS['TSFE'] = new \stdClass();
                $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
                $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
                $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
@@ -328,6 +322,7 @@ class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                        ),
                        'delete' => 'deleted_column'
                );
+               $GLOBALS['TSFE'] = new \stdClass();
                $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
                $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
                $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'), array(), '', FALSE);
index eefd086..7418423 100644 (file)
@@ -29,23 +29,11 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Service;
 class ExtensionServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * Contains backup of $TYPO3_CONF_VARS
-        *
-        * @var array
-        */
-       protected $typo3ConfVars = array();
-
-       /**
         * @var \TYPO3\CMS\Core\Database\DatabaseConnection
         */
        protected $typo3DbBackup;
 
        /**
-        * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current $GLOBALS['TSFE']
-        */
-       protected $tsfeBackup;
-
-       /**
         * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
         */
        protected $mockConfigurationManager;
@@ -56,9 +44,9 @@ class ExtensionServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        protected $extensionService;
 
        public function setUp() {
-               $this->typo3ConfVars = $GLOBALS['TYPO3_CONF_VARS'];
                $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('fullQuoteStr', 'exec_SELECTgetRows'));
+               $GLOBALS['TSFE'] = new \stdClass();
                $this->extensionService = new \TYPO3\CMS\Extbase\Service\ExtensionService();
                $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
                $this->extensionService->injectConfigurationManager($this->mockConfigurationManager);
@@ -100,8 +88,6 @@ class ExtensionServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        }
 
        public function tearDown() {
-               $GLOBALS['TYPO3_CONF_VARS'] = $this->typo3ConfVars;
-               $GLOBALS['TSFE'] = $this->tsfeBackup;
                $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
        }
 
index a8531e6..971148b 100644 (file)
@@ -29,13 +29,6 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
 class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * Enable backup of global and system variables
-        *
-        * @var boolean
-        */
-       protected $backupGlobals = TRUE;
-
-       /**
         * A backup of the global database
         *
         * @var \TYPO3\CMS\Core\Database\DatabaseConnection
@@ -45,12 +38,10 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function setUp() {
                $this->databaseBackup = $GLOBALS['TYPO3_DB'];
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('fullQuoteStr', 'exec_SELECTgetRows'));
-               if (!isset($GLOBALS['TSFE']->tmpl)) {
-                       $GLOBALS['TSFE']->tmpl = new \stdClass();
-               }
-               if (!isset($GLOBALS['TSFE']->tmpl->setup)) {
-                       $GLOBALS['TSFE']->tmpl->setup = array();
-               }
+
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->tmpl = new \stdClass();
+               $GLOBALS['TSFE']->tmpl->setup = array();
                $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = array(
                        '9' => 'CASE',
                        '9.' => array(