diff --git a/libraries/classes/Controllers/Table/OperationsController.php b/libraries/classes/Controllers/Table/OperationsController.php index a27b42b32864..413ee0c3aa76 100644 --- a/libraries/classes/Controllers/Table/OperationsController.php +++ b/libraries/classes/Controllers/Table/OperationsController.php @@ -288,7 +288,7 @@ public function index(): void if ($reread_info) { // to avoid showing the old value (for example the AUTO_INCREMENT) after // a change, clear the cache - $this->dbi->clearTableCache(); + $this->dbi->getCache()->clearTableCache(); $this->dbi->selectDb($db); $GLOBALS['showtable'] = $pma_table->getStatusInfo(null, true); if ($pma_table->isView()) { diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index e72689ea9e84..da9ea4542767 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -13,6 +13,8 @@ use PhpMyAdmin\Dbal\DbiExtension; use PhpMyAdmin\Dbal\DbiMysqli; use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Query\Cache; +use PhpMyAdmin\Query\Generator as QueryGenerator; use PhpMyAdmin\SqlParser\Context; use const E_USER_WARNING; use const LOG_INFO; @@ -108,9 +110,6 @@ class DatabaseInterface implements DbalInterface */ private $_links; - /** @var array Table data cache */ - private $_table_cache; - /** @var array Current user and host cache */ private $_current_user; @@ -134,6 +133,9 @@ class DatabaseInterface implements DbalInterface /** @var Relation */ private $relation; + /** @var Cache */ + private $cache; + /** * @param DbiExtension $ext Object to be used for database queries */ @@ -145,8 +147,8 @@ public function __construct(DbiExtension $ext) $this->_links[self::CONNECT_USER] = 1; $this->_links[self::CONNECT_CONTROL] = 2; } - $this->_table_cache = []; $this->_current_user = []; + $this->cache = new Cache(); $this->types = new Types($this); $this->relation = new Relation($this); } @@ -178,90 +180,9 @@ public function query( return $result; } - /** - * Get a cached value from table cache. - * - * @param array $contentPath Array of the name of the target value - * @param mixed $default Return value on cache miss - * - * @return mixed cached value or default - */ - public function getCachedTableContent(array $contentPath, $default = null) + public function getCache(): Cache { - return Util::getValueByKey($this->_table_cache, $contentPath, $default); - } - - /** - * Set an item in table cache using dot notation. - * - * @param array|null $contentPath Array with the target path - * @param mixed $value Target value - */ - public function cacheTableContent(?array $contentPath, $value): void - { - $loc = &$this->_table_cache; - - if (! isset($contentPath)) { - $loc = $value; - - return; - } - - while (count($contentPath) > 1) { - $key = array_shift($contentPath); - - // If the key doesn't exist at this depth, we will just create an empty - // array to hold the next value, allowing us to create the arrays to hold - // final values at the correct depth. Then we'll keep digging into the - // array. - if (! isset($loc[$key]) || ! is_array($loc[$key])) { - $loc[$key] = []; - } - $loc = &$loc[$key]; - } - - $loc[array_shift($contentPath)] = $value; - } - - /** - * Clear the table cache. - */ - public function clearTableCache(): void - { - $this->_table_cache = []; - } - - /** - * Caches table data so Table does not require to issue - * SHOW TABLE STATUS again - * - * @param array $tables information for tables of some databases - * @param string|bool $table table name - */ - private function _cacheTableData(array $tables, $table): void - { - // Note: I don't see why we would need array_merge_recursive() here, - // as it creates double entries for the same table (for example a double - // entry for Comment when changing the storage engine in Operations) - // Note 2: Instead of array_merge(), simply use the + operator because - // array_merge() renumbers numeric keys starting with 0, therefore - // we would lose a db name that consists only of numbers - - foreach ($tables as $one_database => $its_tables) { - if (isset($this->_table_cache[$one_database])) { - // the + operator does not do the intended effect - // when the cache for one table already exists - if ($table - && isset($this->_table_cache[$one_database][$table]) - ) { - unset($this->_table_cache[$one_database][$table]); - } - $this->_table_cache[$one_database] - += $tables[$one_database]; - } else { - $this->_table_cache[$one_database] = $tables[$one_database]; - } - } + return $this->cache; } /** @@ -433,100 +354,6 @@ public function getForeignKeyConstrains(string $database, array $tables, $link = ); } - /** - * returns a segment of the SQL WHERE clause regarding table name and type - * - * @param array|string $table table(s) - * @param bool $tbl_is_group $table is a table group - * @param string $table_type whether table or view - * - * @return string a segment of the WHERE clause - */ - private function _getTableCondition( - $table, - bool $tbl_is_group, - ?string $table_type - ): string { - // get table information from information_schema - if ($table) { - if (is_array($table)) { - $sql_where_table = 'AND t.`TABLE_NAME` ' - . Util::getCollateForIS() . ' IN (\'' - . implode( - '\', \'', - array_map( - [ - $this, - 'escapeString', - ], - $table - ) - ) - . '\')'; - } elseif ($tbl_is_group === true) { - $sql_where_table = 'AND t.`TABLE_NAME` LIKE \'' - . Util::escapeMysqlWildcards( - $this->escapeString($table) - ) - . '%\''; - } else { - $sql_where_table = 'AND t.`TABLE_NAME` ' - . Util::getCollateForIS() . ' = \'' - . $this->escapeString($table) . '\''; - } - } else { - $sql_where_table = ''; - } - - if ($table_type) { - if ($table_type == 'view') { - $sql_where_table .= " AND t.`TABLE_TYPE` NOT IN ('BASE TABLE', 'SYSTEM VERSIONED')"; - } elseif ($table_type == 'table') { - $sql_where_table .= " AND t.`TABLE_TYPE` IN ('BASE TABLE', 'SYSTEM VERSIONED')"; - } - } - - return $sql_where_table; - } - - /** - * returns the beginning of the SQL statement to fetch the list of tables - * - * @param string[] $this_databases databases to list - * @param string $sql_where_table additional condition - * - * @return string the SQL statement - */ - private function _getSqlForTablesFull($this_databases, string $sql_where_table): string - { - return 'SELECT *,' - . ' `TABLE_SCHEMA` AS `Db`,' - . ' `TABLE_NAME` AS `Name`,' - . ' `TABLE_TYPE` AS `TABLE_TYPE`,' - . ' `ENGINE` AS `Engine`,' - . ' `ENGINE` AS `Type`,' - . ' `VERSION` AS `Version`,' - . ' `ROW_FORMAT` AS `Row_format`,' - . ' `TABLE_ROWS` AS `Rows`,' - . ' `AVG_ROW_LENGTH` AS `Avg_row_length`,' - . ' `DATA_LENGTH` AS `Data_length`,' - . ' `MAX_DATA_LENGTH` AS `Max_data_length`,' - . ' `INDEX_LENGTH` AS `Index_length`,' - . ' `DATA_FREE` AS `Data_free`,' - . ' `AUTO_INCREMENT` AS `Auto_increment`,' - . ' `CREATE_TIME` AS `Create_time`,' - . ' `UPDATE_TIME` AS `Update_time`,' - . ' `CHECK_TIME` AS `Check_time`,' - . ' `TABLE_COLLATION` AS `Collation`,' - . ' `CHECKSUM` AS `Checksum`,' - . ' `CREATE_OPTIONS` AS `Create_options`,' - . ' `TABLE_COMMENT` AS `Comment`' - . ' FROM `information_schema`.`TABLES` t' - . ' WHERE `TABLE_SCHEMA` ' . Util::getCollateForIS() - . ' IN (\'' . implode("', '", $this_databases) . '\')' - . ' ' . $sql_where_table; - } - /** * returns array of all tables in given db or dbs * this function expects unquoted names: @@ -575,8 +402,14 @@ public function getTablesFull( $tables = []; if (! $GLOBALS['cfg']['Server']['DisableIS']) { - $sql_where_table = $this->_getTableCondition( - $table, + $sql_where_table = QueryGenerator::getTableCondition( + is_array($table) ? array_map( + [ + $this, + 'escapeString', + ], + $table + ) : $this->escapeString($table), $tbl_is_group, $table_type ); @@ -596,7 +429,7 @@ public function getTablesFull( $databases ); - $sql = $this->_getSqlForTablesFull($this_databases, $sql_where_table); + $sql = QueryGenerator::getSqlForTablesFull($this_databases, $sql_where_table); // Sort the tables $sql .= ' ORDER BY ' . $sort_by . ' ' . $sort_order; @@ -823,7 +656,7 @@ static function ($a, $b) { // cache table data // so Table does not require to issue SHOW TABLE STATUS again - $this->_cacheTableData($tables, $table); + $this->cache->cacheTableData($tables, $table); if (isset($tables[$database])) { return $tables[$database]; @@ -1398,29 +1231,6 @@ public function getColumnNames( return $fields; } - /** - * Returns SQL for fetching information on table indexes (SHOW INDEXES) - * - * @param string $database name of database - * @param string $table name of the table whose indexes are to be retrieved - * @param string $where additional conditions for WHERE - * - * @return string SQL for getting indexes - */ - public function getTableIndexesSql( - string $database, - string $table, - ?string $where = null - ): string { - $sql = 'SHOW INDEXES FROM ' . Util::backquote($database) . '.' - . Util::backquote($table); - if ($where) { - $sql .= ' WHERE (' . $where . ')'; - } - - return $sql; - } - /** * Returns indexes of a table * @@ -1435,7 +1245,7 @@ public function getTableIndexes( string $table, $link = self::CONNECT_USER ): array { - $sql = $this->getTableIndexesSql($database, $table); + $sql = QueryGenerator::getTableIndexesSql($database, $table); $indexes = $this->fetchResult($sql, null, null, $link); if (! is_array($indexes) || count($indexes) < 1) { diff --git a/libraries/classes/DbTableExists.php b/libraries/classes/DbTableExists.php index 3e3b54c78890..b61a07d7814f 100644 --- a/libraries/classes/DbTableExists.php +++ b/libraries/classes/DbTableExists.php @@ -80,7 +80,7 @@ private static function checkTable(): void $is_table = false; if (strlen($table) > 0) { - $is_table = $dbi->getCachedTableContent([$db, $table], false); + $is_table = $dbi->getCache()->getCachedTableContent([$db, $table], false); if ($is_table) { return; } diff --git a/libraries/classes/Dbal/DbalInterface.php b/libraries/classes/Dbal/DbalInterface.php index fa58c255bf0d..bbd320897b6d 100644 --- a/libraries/classes/Dbal/DbalInterface.php +++ b/libraries/classes/Dbal/DbalInterface.php @@ -31,29 +31,6 @@ public function query( bool $cache_affected_rows = true ); - /** - * Get a cached value from table cache. - * - * @param array $contentPath Array of the name of the target value - * @param mixed $default Return value on cache miss - * - * @return mixed cached value or default - */ - public function getCachedTableContent(array $contentPath, $default = null); - - /** - * Set an item in table cache using dot notation. - * - * @param array|null $contentPath Array with the target path - * @param mixed $value Target value - */ - public function cacheTableContent(?array $contentPath, $value): void; - - /** - * Clear the table cache. - */ - public function clearTableCache(): void; - /** * runs a query and returns the result * @@ -265,17 +242,6 @@ public function getColumnNames( $link = DatabaseInterface::CONNECT_USER ): ?array; - /** - * Returns SQL for fetching information on table indexes (SHOW INDEXES) - * - * @param string $database name of database - * @param string $table name of the table whose indexes are to be retrieved - * @param string $where additional conditions for WHERE - * - * @return string SQL for getting indexes - */ - public function getTableIndexesSql(string $database, string $table, ?string $where = null): string; - /** * Returns indexes of a table * diff --git a/libraries/classes/Query/Cache.php b/libraries/classes/Query/Cache.php new file mode 100644 index 000000000000..b50c719d3288 --- /dev/null +++ b/libraries/classes/Query/Cache.php @@ -0,0 +1,104 @@ + $_) { + if (isset($this->tableCache[$one_database])) { + // the + operator does not do the intended effect + // when the cache for one table already exists + if ($table + && isset($this->tableCache[$one_database][$table]) + ) { + unset($this->tableCache[$one_database][$table]); + } + $this->tableCache[$one_database] + += $tables[$one_database]; + } else { + $this->tableCache[$one_database] = $tables[$one_database]; + } + } + } + + /** + * Set an item in table cache using dot notation. + * + * @param array|null $contentPath Array with the target path + * @param mixed $value Target value + */ + public function cacheTableContent(?array $contentPath, $value): void + { + $loc = &$this->tableCache; + + if (! isset($contentPath)) { + $loc = $value; + + return; + } + + while (count($contentPath) > 1) { + $key = array_shift($contentPath); + + // If the key doesn't exist at this depth, we will just create an empty + // array to hold the next value, allowing us to create the arrays to hold + // final values at the correct depth. Then we'll keep digging into the + // array. + if (! isset($loc[$key]) || ! is_array($loc[$key])) { + $loc[$key] = []; + } + $loc = &$loc[$key]; + } + + $loc[array_shift($contentPath)] = $value; + } + + /** + * Get a cached value from table cache. + * + * @param array $contentPath Array of the name of the target value + * @param mixed $default Return value on cache miss + * + * @return mixed cached value or default + */ + public function getCachedTableContent(array $contentPath, $default = null) + { + return Util::getValueByKey($this->tableCache, $contentPath, $default); + } + + public function getCache(): array + { + return $this->tableCache; + } + + public function clearTableCache(): void + { + $this->tableCache = []; + } +} diff --git a/libraries/classes/Query/Generator.php b/libraries/classes/Query/Generator.php new file mode 100644 index 000000000000..f4c40f72a21e --- /dev/null +++ b/libraries/classes/Query/Generator.php @@ -0,0 +1,123 @@ +_dbi->getCachedTableContent([$db, $table]) != null + if ($this->_dbi->getCache()->getCachedTableContent([$db, $table]) != null || $GLOBALS['cfg']['Server']['DisableIS'] ) { $type = $this->getStatusInfo('TABLE_TYPE'); @@ -320,16 +321,18 @@ public function getStatusInfo( $disable_error = true; } + $cachedResult = $this->_dbi->getCache()->getCachedTableContent([$db, $table]); + // sometimes there is only one entry (ExactRows) so // we have to get the table's details - if ($this->_dbi->getCachedTableContent([$db, $table]) == null + if ($cachedResult === null || $force_read - || count($this->_dbi->getCachedTableContent([$db, $table])) === 1 + || count($cachedResult) === 1 ) { $this->_dbi->getTablesFull($db, $table); } - if ($this->_dbi->getCachedTableContent([$db, $table]) == null) { + if ($cachedResult === null) { // happens when we enter the table creation dialog // or when we really did not get any status info, for example // when $table == 'TABLE_NAMES' after the user tried SHOW TABLES @@ -337,13 +340,13 @@ public function getStatusInfo( } if ($info === null) { - return $this->_dbi->getCachedTableContent([$db, $table]); + return $cachedResult; } // array_key_exists allows for null values if (! array_key_exists( $info, - $this->_dbi->getCachedTableContent([$db, $table]) + $cachedResult ) ) { if (! $disable_error) { @@ -356,7 +359,7 @@ public function getStatusInfo( return false; } - return $this->_dbi->getCachedTableContent([$db, $table, $info]); + return $this->_dbi->getCache()->getCachedTableContent([$db, $table, $info]); } /** @@ -365,7 +368,7 @@ public function getStatusInfo( * @return string Return storage engine info if it is set for * the selected table else return blank. */ - public function getStorageEngine() + public function getStorageEngine(): string { $table_storage_engine = $this->getStatusInfo('ENGINE', false, true); if ($table_storage_engine === false) { @@ -728,8 +731,8 @@ public function countRecords($force_exact = false) $db = $this->_db_name; $table = $this->_name; - if ($this->_dbi->getCachedTableContent([$db, $table, 'ExactRows']) != null) { - return $this->_dbi->getCachedTableContent( + if ($this->_dbi->getCache()->getCachedTableContent([$db, $table, 'ExactRows']) != null) { + return $this->_dbi->getCache()->getCachedTableContent( [ $db, $table, @@ -740,12 +743,12 @@ public function countRecords($force_exact = false) $row_count = false; if (! $force_exact) { - if (($this->_dbi->getCachedTableContent([$db, $table, 'Rows']) == null) + if (($this->_dbi->getCache()->getCachedTableContent([$db, $table, 'Rows']) == null) && ! $is_view ) { $tmp_tables = $this->_dbi->getTablesFull($db, $table); if (isset($tmp_tables[$table])) { - $this->_dbi->cacheTableContent( + $this->_dbi->getCache()->cacheTableContent( [ $db, $table, @@ -754,8 +757,8 @@ public function countRecords($force_exact = false) ); } } - if ($this->_dbi->getCachedTableContent([$db, $table, 'Rows']) != null) { - $row_count = $this->_dbi->getCachedTableContent( + if ($this->_dbi->getCache()->getCachedTableContent([$db, $table, 'Rows']) != null) { + $row_count = $this->_dbi->getCache()->getCachedTableContent( [ $db, $table, @@ -805,7 +808,7 @@ public function countRecords($force_exact = false) } } if ($row_count) { - $this->_dbi->cacheTableContent([$db, $table, 'ExactRows'], $row_count); + $this->_dbi->getCache()->cacheTableContent([$db, $table, 'ExactRows'], $row_count); } return $row_count; @@ -1689,7 +1692,7 @@ public function rename($new_name, $new_db = null) */ public function getUniqueColumns($backquoted = true, $fullName = true) { - $sql = $this->_dbi->getTableIndexesSql( + $sql = QueryGenerator::getTableIndexesSql( $this->getDbName(), $this->getName(), 'Non_unique = 0' @@ -1767,7 +1770,7 @@ private function _formatColumns(array $indexed, $backquoted, $fullName) */ public function getIndexedColumns($backquoted = true, $fullName = true) { - $sql = $this->_dbi->getTableIndexesSql( + $sql = QueryGenerator::getTableIndexesSql( $this->getDbName(), $this->getName(), '' diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 70ddf1ff4d73..ef80429694ca 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -956,7 +956,7 @@ parameters: path: libraries/classes/Database/Triggers.php - - message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\DatabaseInterface\\:\\:_cacheTableData\\(\\) expects bool\\|string, array\\|string given\\.$#" + message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\Query\\\\Cache\\:\\:cacheTableData\\(\\) expects bool\\|string, array\\|string given\\.$#" count: 1 path: libraries/classes/DatabaseInterface.php @@ -4950,11 +4950,6 @@ parameters: count: 1 path: test/classes/SystemDatabaseTest.php - - - message: "#^Access to private property PhpMyAdmin\\\\DatabaseInterface&PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\:\\:\\$_table_cache\\.$#" - count: 1 - path: test/classes/TableTest.php - - message: "#^Parameter \\#1 \\$table_name of class PhpMyAdmin\\\\Table constructor expects string, null given\\.$#" count: 2 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f1f3cf2dd99b..0d45d9814c02 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + Util::formatByteDown($value, $limes, $comma) @@ -250,6 +250,9 @@ $formatted_size $unit + + $selected + $sub_part @@ -1284,12 +1287,10 @@ - + + $server_msg ceil($count / $max_count) - - $server_msg - @@ -2076,8 +2077,7 @@ $com_rs $com_rs - - $cfgRelation + $this->queryAsControlUser($upd_query) $this->dbi->insertId(DatabaseInterface::CONNECT_CONTROL) @@ -2507,8 +2507,7 @@ - - $geom_funcs + $geom_funcs @@ -2638,9 +2637,8 @@ $value - + $wktval - $regex mb_strrpos($columnspec, ')') diff --git a/test/classes/Display/ExportTest.php b/test/classes/Display/ExportTest.php index 98ead2567289..bee491df2945 100644 --- a/test/classes/Display/ExportTest.php +++ b/test/classes/Display/ExportTest.php @@ -113,7 +113,7 @@ public function testGetHtmlForOptions() $num_tables_str = '10'; $unlim_num_rows_str = 'unlim_num_rows_str'; //$single_table = "single_table"; - $GLOBALS['dbi']->cacheTableContent([$db, $table, 'ENGINE'], 'MERGE'); + $GLOBALS['dbi']->getCache()->cacheTableContent([$db, $table, 'ENGINE'], 'MERGE'); $columns_info = [ 'test_column1' => ['COLUMN_NAME' => 'test_column1'], diff --git a/test/classes/TableTest.php b/test/classes/TableTest.php index 28795f1f35b1..dd940ee9a67b 100644 --- a/test/classes/TableTest.php +++ b/test/classes/TableTest.php @@ -11,8 +11,10 @@ use PhpMyAdmin\Index; use PhpMyAdmin\Relation; use PhpMyAdmin\Table; +use PhpMyAdmin\Query\Cache; use PhpMyAdmin\Tests\Stubs\DbiDummy; use stdClass; +use ReflectionClass; /** * Tests behaviour of Table class @@ -89,7 +91,7 @@ public function exists($name) . ' WHERE TABLE_SCHEMA = \'db_data\'' . ' AND TABLE_NAME = \'table_data\''; - $getUniqueColumns_sql = 'select unique column'; + $getUniqueColumns_sql = 'SHOW INDEXES FROM `PMA`.`PMA_BookMark`'; $fetchResult = [ [ @@ -146,7 +148,7 @@ public function exists($name) ], ], [ - $getUniqueColumns_sql, + $getUniqueColumns_sql . ' WHERE (Non_unique = 0)', [ 'Key_name', null, @@ -234,12 +236,9 @@ public function exists($name) ) ); - $dbi->_table_cache['PMA']['PMA_BookMark'] = [ - 'ENGINE' => true, - 'Create_time' => true, - 'TABLE_TYPE' => true, - 'Comment' => true, - ]; + $cache = new Cache(); + $dbi->expects($this->any())->method('getCache') + ->will($this->returnValue($cache)); $databases = []; $database_name = 'PMA'; @@ -286,9 +285,6 @@ public function exists($name) $dbi->expects($this->any())->method('query') ->will($this->returnValue($create_sql)); - $dbi->expects($this->any())->method('getTableIndexesSql') - ->will($this->returnValue($getUniqueColumns_sql)); - $dbi->expects($this->any())->method('insertId') ->will($this->returnValue(10)); @@ -933,9 +929,6 @@ public function testIsMergeCase1() $tableObj->isMerge() ); - $GLOBALS['dbi']->expects($this->any()) - ->method('getCachedTableContent') - ->will($this->returnValue(['table_name' => 'PMA_BookMark'])); $tableObj = new Table('PMA_BookMark', 'PMA'); $this->assertFalse( $tableObj->isMerge() @@ -949,28 +942,15 @@ public function testIsMergeCase1() */ public function testIsMergeCase2() { - $map = [ - [ - [ - 'PMA', - 'PMA_BookMark', - ], - null, - ['ENGINE' => 'MERGE'], - ], + /** @var DatabaseInterface $dbi */ + global $dbi; + + $dbi->getCache()->cacheTableContent( + ['PMA', 'PMA_BookMark'], [ - [ - 'PMA', - 'PMA_BookMark', - 'ENGINE', - ], - null, - 'MERGE', - ], - ]; - $GLOBALS['dbi']->expects($this->any()) - ->method('getCachedTableContent') - ->will($this->returnValueMap($map)); + 'ENGINE' => 'MERGE', + ] + ); $tableObj = new Table('PMA_BookMark', 'PMA'); $this->assertTrue( @@ -985,28 +965,15 @@ public function testIsMergeCase2() */ public function testIsMergeCase3() { - $map = [ - [ - [ - 'PMA', - 'PMA_BookMark', - ], - null, - ['ENGINE' => 'MRG_MYISAM'], - ], + /** @var DatabaseInterface $dbi */ + global $dbi; + + $dbi->getCache()->cacheTableContent( + ['PMA', 'PMA_BookMark'], [ - [ - 'PMA', - 'PMA_BookMark', - 'ENGINE', - ], - null, - 'MRG_MYISAM', - ], - ]; - $GLOBALS['dbi']->expects($this->any()) - ->method('getCachedTableContent') - ->will($this->returnValueMap($map)); + 'ENGINE' => 'MRG_MYISAM', + ] + ); $tableObj = new Table('PMA_BookMark', 'PMA'); $this->assertTrue( @@ -1015,35 +982,10 @@ public function testIsMergeCase3() } /** - * Test for isMerge -- when ENGINE info is ISDB - * - * @return void + * Test for Table::isMerge -- when ENGINE info is ISDB */ - public function testIsMergeCase4() + public function testIsMergeCase4(): void { - $map = [ - [ - [ - 'PMA', - 'PMA_BookMark', - ], - null, - ['ENGINE' => 'ISDB'], - ], - [ - [ - 'PMA', - 'PMA_BookMark', - 'ENGINE', - ], - null, - 'ISDB', - ], - ]; - $GLOBALS['dbi']->expects($this->any()) - ->method('getCachedTableContent') - ->will($this->returnValueMap($map)); - $tableObj = new Table('PMA_BookMark', 'PMA'); $this->assertFalse( $tableObj->isMerge() @@ -1433,47 +1375,17 @@ public function testCheckIfMinRecordsExist() } /** - * Test for countRecords - * - * @return void + * Test for Table::countRecords */ - public function testCountRecords() + public function testCountRecords(): void { - $map = [ - [ - [ - 'PMA', - 'PMA_BookMark', - ], - null, - [ - 'Comment' => 'Comment222', - 'TABLE_TYPE' => 'VIEW', - ], - ], - [ - [ - 'PMA', - 'PMA_BookMark', - 'TABLE_TYPE', - ], - null, - 'VIEW', - ], - ]; - $GLOBALS['dbi']->expects($this->any()) - ->method('getCachedTableContent') - ->will($this->returnValueMap($map)); - $table = 'PMA_BookMark'; $db = 'PMA'; $tableObj = new Table($table, $db); - $return = $tableObj->countRecords(true); - $expect = 20; $this->assertEquals( - $expect, - $return + 20, + $tableObj->countRecords(true) ); }