[BUGFIX] PHP 7.1 unit tests 41/48841/5
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 7 Jul 2016 11:20:20 +0000 (13:20 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 7 Jul 2016 12:10:38 +0000 (14:10 +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/48841
Reviewed-by: Sebastian Bumann <bumann.sebastian@gmail.com>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Tested-by: Sebastian Bumann <bumann.sebastian@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
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 42dfd5c..4201de5 100644 (file)
@@ -79,12 +79,10 @@ class DatabaseConnectionTest extends UnitTestCase
             ->will($this->returnCallback(function ($data) {
                 return $data;
             }));
-        $mysqliMock = $this->createMock('mysqli');
-        $mysqliMock
-            ->expects($this->once())
-            ->method('query')
-            ->with("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ({$binaryString})");
-        $subject->_set('link', $mysqliMock);
+        $mysqliProphecy = $this->prophesize(\mysqli::class);
+        $mysqliProphecy->query("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ({$binaryString})")
+            ->shouldBeCalled();
+        $subject->_set('link', $mysqliProphecy->reveal());
 
         $subject->exec_INSERTquery($this->testTable, [$this->testField => $binaryString]);
     }
@@ -106,12 +104,10 @@ class DatabaseConnectionTest extends UnitTestCase
             ->will($this->returnCallback(function ($data) {
                 return $data;
             }));
-        $mysqliMock = $this->createMock('mysqli');
-        $mysqliMock
-            ->expects($this->once())
-            ->method('query')
-            ->with("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ({$testStringWithBinary})");
-        $subject->_set('link', $mysqliMock);
+        $mysqliProphecy = $this->prophesize(\mysqli::class);
+        $mysqliProphecy->query("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ({$testStringWithBinary})")
+            ->shouldBeCalled();
+        $subject->_set('link', $mysqliProphecy->reveal());
 
         $subject->exec_INSERTquery($this->testTable, [$this->testField => $testStringWithBinary]);
     }
@@ -577,12 +573,9 @@ class DatabaseConnectionTest extends UnitTestCase
         $subject->_set('isConnected', true);
         $subject->_set('databaseName', $this->testTable);
 
-        $mysqliMock = $this->getMockBuilder('mysqli')->getMock();
-        $mysqliMock
-            ->expects($this->once())
-            ->method('select_db')
-            ->with($this->equalTo($this->testTable))->will($this->returnValue(true));
-        $subject->_set('link', $mysqliMock);
+        $mysqliProphecy = $this->prophesize(\mysqli::class);
+        $mysqliProphecy->select_db($this->testTable)->shouldBeCalled()->willReturn(true);
+        $subject->_set('link', $mysqliProphecy->reveal());
 
         $this->assertTrue($subject->sql_select_db());
     }
@@ -595,16 +588,14 @@ class DatabaseConnectionTest extends UnitTestCase
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = GeneralUtility::SYSLOG_SEVERITY_WARNING;
 
         /** @var DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface $subject */
-        $subject = $this->getAccessibleMock(DatabaseConnection::class, ['dummy'], [], '', false);
+        $subject = $this->getAccessibleMock(DatabaseConnection::class, ['sql_error'], [], '', false);
         $subject->_set('isConnected', true);
         $subject->_set('databaseName', $this->testTable);
+        $subject->expects($this->any())->method('sql_error')->will($this->returnValue(''));
 
-        $mysqliMock = $this->getMockBuilder('mysqli')->getMock();
-        $mysqliMock
-            ->expects($this->once())
-            ->method('select_db')
-            ->with($this->equalTo($this->testTable))->will($this->returnValue(false));
-        $subject->_set('link', $mysqliMock);
+        $mysqliProphecy = $this->prophesize(\mysqli::class);
+        $mysqliProphecy->select_db($this->testTable)->shouldBeCalled()->willReturn(false);
+        $subject->_set('link', $mysqliProphecy->reveal());
 
         $this->assertFalse($subject->sql_select_db());
     }
index 7fdec76..d236078 100644 (file)
@@ -84,8 +84,15 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
             ->getMock();
         $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;
 
         return $tsfe;
     }
index 6d7935f..f41d44a 100644 (file)
@@ -106,7 +106,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->createMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class);
-        $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']);