[BUGFIX] PHP 5.4 unit test warnings
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 2 Nov 2012 00:14:59 +0000 (01:14 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 2 Nov 2012 00:22:55 +0000 (01:22 +0100)
PHP 5.4 throws warnings "Creating default object from empty value"
warnings 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.

Fixes: #42612
Releases: 6.0

Change-Id: Ia330dfa96a8374ffc30908c968eafcf350bf79d0
Reviewed-on: http://review.typo3.org/16118
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/EmailViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Security/IfHasRoleViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Uri/EmailViewHelperTest.php

index 1f7c25a..e47ddcf 100644 (file)
@@ -32,22 +32,17 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
 
        public function setUp() {
                parent::setUp();
-               $this->cObjBackup = $GLOBALS['TSFE']->cObj;
+               $GLOBALS['TSFE'] = new \stdClass();
                $GLOBALS['TSFE']->cObj = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array(), array(), '', FALSE);
                $this->viewHelper = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Fluid\\ViewHelpers\\Link\\EmailViewHelper'), array('renderChildren'));
                $this->injectDependenciesIntoViewHelper($this->viewHelper);
                $this->viewHelper->initializeArguments();
        }
 
-       public function tearDown() {
-               $GLOBALS['TSFE']->cObj = $this->cObjBackup;
-       }
-
        /**
         * @test
         */
        public function renderCorrectlySetsTagNameAndAttributesAndContent() {
-               //$GLOBALS['TSFE']->cObj->expects($this->once())->method('getMailTo')->with('some@email.tld', 'some@email.tld')->will($this->returnValue(array('mailto:some@email.tld', 'some@email.tld')));
                $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
                $mockTagBuilder->expects($this->once())->method('setTagName')->with('a');
                $mockTagBuilder->expects($this->once())->method('addAttribute')->with('href', 'mailto:some@email.tld');
@@ -62,7 +57,6 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
         * @test
         */
        public function renderSetsTagContentToEmailIfRenderChildrenReturnNull() {
-               //$GLOBALS['TSFE']->cObj->expects($this->once())->method('getMailTo')->with('some@email.tld', 'some@email.tld')->will($this->returnValue(array('mailto:some@email.tld', 'some@email.tld')));
                $mockTagBuilder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder', array('setTagName', 'addAttribute', 'setContent'));
                $mockTagBuilder->expects($this->once())->method('setContent')->with('some@email.tld');
                $this->viewHelper->_set('tag', $mockTagBuilder);
index 2d46e8e..8b63718 100644 (file)
@@ -32,16 +32,11 @@ class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vi
         */
        protected $viewHelper;
 
-       /**
-        * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
-        */
-       protected $tsfeBackup;
-
        public function setUp() {
                parent::setUp();
-               $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
                $GLOBALS['TSFE'] = new \stdClass();
                $GLOBALS['TSFE']->loginUser = 1;
+               $GLOBALS['TSFE']->fe_user = new \stdClass();
                $GLOBALS['TSFE']->fe_user->groupData = array(
                        'uid' => array(1, 2),
                        'title' => array('Editor', 'OtherRole')
@@ -53,10 +48,6 @@ class IfHasRoleViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Vi
                $this->viewHelper->initializeArguments();
        }
 
-       public function tearDown() {
-               $GLOBALS['TSFE'] = $this->tsfeBackup;
-       }
-
        /**
         * @test
         */
index d5a400f..bfb2348 100644 (file)
@@ -32,29 +32,19 @@ class EmailViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHe
         */
        protected $viewHelper;
 
-       /**
-        * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
-        */
-       protected $cObjBackup;
-
        public function setUp() {
                parent::setUp();
-               $this->cObjBackup = $GLOBALS['TSFE']->cObj;
+               $GLOBALS['TSFE'] = new \stdClass();
                $GLOBALS['TSFE']->cObj = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array(), array(), '', FALSE);
                $this->viewHelper = new \TYPO3\CMS\Fluid\ViewHelpers\Uri\EmailViewHelper();
                $this->injectDependenciesIntoViewHelper($this->viewHelper);
                $this->viewHelper->initializeArguments();
        }
 
-       public function tearDown() {
-               $GLOBALS['TSFE']->cObj = $this->cObjBackup;
-       }
-
        /**
         * @test
         */
        public function renderReturnsFirstResultOfGetMailTo() {
-               #$GLOBALS['TSFE']->cObj->expects($this->once())->method('getMailTo')->with('some@email.tld', 'some@email.tld')->will($this->returnValue(array('mailto:some@email.tld', 'some@email.tld')));
                $this->viewHelper->initialize();
                $actualResult = $this->viewHelper->render('some@email.tld');
                $this->assertEquals('mailto:some@email.tld', $actualResult);