[BUGFIX] Incomplete mocking and backups it tests
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 9 Sep 2012 09:55:21 +0000 (11:55 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 9 Sep 2012 10:06:42 +0000 (12:06 +0200)
Fix two systematical warnings raised by running the unit tests:

* The DataMapperTest mocks Persistence\Generic\Mapper\DataMap which
raises warnings that the mocked class expects two constructor arguments
that are not given. The mocks are adapted to not call the constructor.

* Incomplete backups in ExtensionUtilityTest destroys
$GLOBALS['TYPO3_DB'] database handle. Fixed by using the usual
$backupGlobals and blackList code from other tests.

Change-Id: I14a22bb2e65ff2f751466e63d280d5fdf5f9be17
Resolves: #40768
Releases: 6.0
Reviewed-on: http://review.typo3.org/14474
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapperTest.php
typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php

index c0b6bae..fb21574 100644 (file)
@@ -113,7 +113,7 @@ class DataMapperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function fetchRelatedEagerReturnsNullForEmptyRelationHasOne() {
                $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
                $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_ONE);
-               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'));
+               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
                $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
                $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'));
                $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
@@ -129,7 +129,7 @@ class DataMapperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        public function fetchRelatedEagerReturnsEmptyArrayForEmptyRelationNotHasOne() {
                $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
                $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_BELONGS_TO_MANY);
-               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'));
+               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
                $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
                $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'));
                $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
index 1ec84ca..1ee5681 100644 (file)
@@ -32,21 +32,30 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
 class ExtensionUtilityTest extends \tx_phpunit_testcase {
 
        /**
-        * Contains backup of $TYPO3_CONF_VARS
+        * Enable backup of global and system variables
+        *
+        * @var boolean
+        */
+       protected $backupGlobals = TRUE;
+
+       /**
+        * Exclude TYPO3_DB from backup/ restore of $GLOBALS
+        * because resource types cannot be handled during serializing
         *
         * @var array
         */
-       protected $typo3ConfVars = array();
+       protected $backupGlobalsBlacklist = array('TYPO3_DB');
 
        /**
-        * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController contains a backup of the current $GLOBALS['TSFE']
+        * A backup of the global database
+        *
+        * @var \TYPO3\CMS\Core\Database\DatabaseConnection
         */
-       protected $tsfeBackup;
+       protected $databaseBackup = NULL;
 
        public function setUp() {
-               $this->typo3ConfVars = $GLOBALS['TYPO3_CONF_VARS'];
+               $this->databaseBackup = $GLOBALS['TYPO3_DB'];
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('fullQuoteStr', 'exec_SELECTgetRows'));
-               $this->tsfeBackup = $GLOBALS['TSFE'];
                if (!isset($GLOBALS['TSFE']->tmpl)) {
                        $GLOBALS['TSFE']->tmpl = new \stdClass();
                }
@@ -83,8 +92,7 @@ class ExtensionUtilityTest extends \tx_phpunit_testcase {
        }
 
        public function tearDown() {
-               $GLOBALS['TYPO3_CONF_VARS'] = $this->typo3ConfVars;
-               $GLOBALS['TSFE'] = $this->tsfeBackup;
+               $GLOBALS['TYPO3_DB'] = $this->databaseBackup;
        }
 
        /**