[BUGFIX] PHP 7.1 unit tests 43/48843/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 7 Jul 2016 11:20:20 +0000 (13:20 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 7 Jul 2016 13:23:32 +0000 (15:23 +0200)
Fix a couple of unit tests that fail with PHP 7.1:

* The phpunit mock builder seems to have minor issues mocking
mysqli correctly. This leads so slightly different method
signatures and PHP 7.1 is a bit more picky about those details.
Switching to prophecy on affected tests solves the issue.

* $tsfe->config is initialized as string, calling
$tsfe->config['foo']['bar'] = 'baz'; raises an error
"Error: Cannot use assign-op operators with string offsets".
Cleaning the assignment solves the issue.

Change-Id: I81f3a75e5b682064c6a43f989f0cf862e2d1bc6e
Resolves: #76980
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/48843
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Unit/Database/DatabaseConnectionTest.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php
typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php

index ae6bae6..00987a1 100644 (file)
@@ -43,12 +43,10 @@ class DatabaseConnectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
             ->will($this->returnCallback(function ($data) {
                 return $data;
             }));
-        $mysqliMock = $this->getMock('mysqli');
-        $mysqliMock
-            ->expects($this->once())
-            ->method('query')
-            ->with('INSERT INTO aTable (fieldblob) VALUES (' . $binaryString . ')');
-        $subject->_set('link', $mysqliMock);
+        $mysqliProphecy = $this->prophesize(\mysqli::class);
+        $mysqliProphecy->query('INSERT INTO aTable (fieldblob) VALUES (' . $binaryString . ')')
+            ->shouldBeCalled();
+        $subject->_set('link', $mysqliProphecy->reveal());
 
         $subject->exec_INSERTquery('aTable', array('fieldblob' => $binaryString));
     }
@@ -69,12 +67,10 @@ class DatabaseConnectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
             ->will($this->returnCallback(function ($data) {
                 return $data;
             }));
-        $mysqliMock = $this->getMock('mysqli');
-        $mysqliMock
-            ->expects($this->once())
-            ->method('query')
-            ->with('INSERT INTO aTable (fieldblob) VALUES (' . $testStringWithBinary . ')');
-        $subject->_set('link', $mysqliMock);
+        $mysqliProphecy = $this->prophesize(\mysqli::class);
+        $mysqliProphecy->query('INSERT INTO aTable (fieldblob) VALUES (' . $testStringWithBinary . ')')
+            ->shouldBeCalled();
+        $subject->_set('link', $mysqliProphecy->reveal());
 
         $subject->exec_INSERTquery('aTable', array('fieldblob' => $testStringWithBinary));
     }
index 4b5ffb6..0ea2290 100644 (file)
@@ -83,9 +83,17 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
         ), array(), '', false);
         $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback(array($this, 'INTincScript_processCallback')));
         $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
-        $tsfe->config['INTincScript_ext']['divKey'] = '679b52796e75d474ccbbed486b6837ab';
-        $tsfe->config['INTincScript'] = array('INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => array());
+        $config = [
+            'INTincScript_ext' => [
+                'divKey' => '679b52796e75d474ccbbed486b6837ab',
+            ],
+            'INTincScript' => [
+                'INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => [],
+            ]
+        ];
+        $tsfe->config = $config;
         $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
+
         return $tsfe;
     }
 
index 844b6e2..7e4d8a8 100644 (file)
@@ -104,7 +104,12 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $absRefPrefix = '/' . $this->getUniqueId();
         $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
         $GLOBALS['TSFE'] = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array(), '', false);
-        $GLOBALS['TSFE']->config['config']['absRefPrefix'] = $absRefPrefix;
+        $config = [
+            'config' => [
+                'absRefPrefix' => $absRefPrefix,
+            ],
+        ];
+        $GLOBALS['TSFE']->config = $config;
         $result = $this->subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
         $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);