[FOLLOWUP][TASK] Doctrine: migrate $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery 64/47964/2
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 29 Apr 2016 08:22:29 +0000 (10:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 29 Apr 2016 09:40:10 +0000 (11:40 +0200)
Fix unit test for Typo3DatabaseBackend

Resolves: #75969
Releases: master
Change-Id: I61049768b2981f7b1a93ab371fd31c0a58edc474
Reviewed-on: https://review.typo3.org/47964
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Unit/Cache/Backend/Typo3DatabaseBackendTest.php

index 80b5318..ce65515 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Cache\Backend;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use Prophecy\Argument;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -485,15 +486,16 @@ class Typo3DatabaseBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $backend = $this->getMock(\TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, array('dummy'), array('Testing'));
         $this->setUpMockFrontendOfBackend($backend);
 
-        $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array(), array(), '', false);
-        $GLOBALS['TYPO3_DB']
-            ->expects($this->at(0))
-            ->method('exec_TRUNCATEquery')
-            ->with('cf_Testing');
-        $GLOBALS['TYPO3_DB']
-            ->expects($this->at(1))
-            ->method('exec_TRUNCATEquery')
-            ->with('cf_Testing_tags');
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->truncate('cf_Testing')->shouldBeCalled()->willReturn(0);
+        $connectionProphet->truncate('cf_Testing_tags')->shouldBeCalled()->willReturn(0);
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getConnectionForTable(Argument::cetera())->willReturn($connectionProphet->reveal());
+
+        // Two instances are required as there are different tables being cleared
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
 
         $backend->flush();
     }