TYPO3  7.6
AbstractTestCase.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Dbal\Tests\Unit\Database;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
19 require_once __DIR__ . '/../../../../adodb/adodb/adodb.inc.php';
20 require_once __DIR__ . '/../../../../adodb/adodb/drivers/adodb-mssql.inc.php';
21 require_once __DIR__ . '/../../../../adodb/adodb/drivers/adodb-oci8.inc.php';
22 require_once __DIR__ . '/../../../../adodb/adodb/drivers/adodb-postgres7.inc.php';
23 
27 abstract class AbstractTestCase extends \TYPO3\CMS\Core\Tests\UnitTestCase
28 {
37  protected function prepareSubject($driver, array $configuration)
38  {
40  $subject = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\DatabaseConnection::class, array('getFieldInfoCache'), array(), '', false);
41 
42  $subject->conf = $configuration;
43 
44  // Disable caching
45  $mockCacheFrontend = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, array(), array(), '', false);
46  $subject->expects($this->any())->method('getFieldInfoCache')->will($this->returnValue($mockCacheFrontend));
47 
48  // Inject SqlParser - Its logic is tested with the tests, too.
49  $sqlParser = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\SqlParser::class, array('dummy'), array(), '', false);
50  $sqlParser->_set('databaseConnection', $subject);
51  $sqlParser->_set('sqlCompiler', GeneralUtility::makeInstance(\TYPO3\CMS\Dbal\Database\SqlCompilers\Adodb::class, $subject));
52  $sqlParser->_set('nativeSqlCompiler', GeneralUtility::makeInstance(\TYPO3\CMS\Dbal\Database\SqlCompilers\Mysql::class, $subject));
53  $subject->SQLparser = $sqlParser;
54 
55  // Mock away schema migration service from install tool
56  $installerSqlMock = $this->getMock(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class, array('getFieldDefinitions_fileContent'), array(), '', false);
57  $installerSqlMock->expects($this->any())->method('getFieldDefinitions_fileContent')->will($this->returnValue(array()));
58  $subject->_set('installerSql', $installerSqlMock);
59 
60  $subject->initialize();
61 
62  // Fake a working connection
63  $handlerKey = '_DEFAULT';
64  $subject->lastHandlerKey = $handlerKey;
65  $adodbDriverClass = '\ADODB_' . $driver;
66  $subject->handlerInstance[$handlerKey] = new $adodbDriverClass();
67  $subject->handlerInstance[$handlerKey]->DataDictionary = NewDataDictionary($subject->handlerInstance[$handlerKey]);
68  $subject->handlerInstance[$handlerKey]->_connectionID = rand(1, 1000);
69 
70  return $subject;
71  }
72 
73 
80  protected function cleanSql($sql)
81  {
82  if (!is_string($sql)) {
83  return $sql;
84  }
85  $sql = str_replace("\n", ' ', $sql);
86  $sql = preg_replace('/\\s+/', ' ', $sql);
87  return trim($sql);
88  }
89 }