Add methods to DbiDummy and AbstractTestCase to control changing databases
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
parent
5837b691d2
commit
2c28a715b4
@ -105,6 +105,16 @@ abstract class AbstractTestCase extends TestCase
|
||||
$this->assertSame([], $unUsedQueries, 'Some queries where not used !');
|
||||
}
|
||||
|
||||
protected function assertAllSelectsConsumed(): void
|
||||
{
|
||||
$unUsedSelects = $this->dummyDbi->getUnUsedDatabaseSelects();
|
||||
$this->assertSame(
|
||||
[],
|
||||
$unUsedSelects,
|
||||
'Some database selects where not used !'
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadContainerBuilder(): void
|
||||
{
|
||||
global $containerBuilder;
|
||||
|
||||
@ -35,10 +35,11 @@ class BookmarkTest extends AbstractTestCase
|
||||
public function testGetParams(): void
|
||||
{
|
||||
$this->assertTrue(Cache::remove('Bookmark.params'), 'The cache needs to be clean');
|
||||
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->assertFalse(
|
||||
Bookmark::getParams($GLOBALS['cfg']['Server']['user'])
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,9 +48,11 @@ class BookmarkTest extends AbstractTestCase
|
||||
public function testGetParamsFromCache(): void
|
||||
{
|
||||
$this->assertTrue(Cache::remove('Bookmark.params'), 'The cache needs to be clean');
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->assertFalse(
|
||||
Bookmark::getParams($GLOBALS['cfg']['Server']['user'])
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$this->assertTrue(Cache::set('Bookmark.params', ['cacheworks' => true]), 'The cache should to be filled');
|
||||
$this->assertSame(
|
||||
['cacheworks' => true],
|
||||
@ -62,6 +65,7 @@ class BookmarkTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetList(): void
|
||||
{
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->assertEquals(
|
||||
[],
|
||||
Bookmark::getList(
|
||||
@ -70,6 +74,7 @@ class BookmarkTest extends AbstractTestCase
|
||||
'phpmyadmin'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +82,7 @@ class BookmarkTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGet(): void
|
||||
{
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->assertNull(
|
||||
Bookmark::get(
|
||||
$GLOBALS['dbi'],
|
||||
@ -85,6 +91,7 @@ class BookmarkTest extends AbstractTestCase
|
||||
'1'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,6 +112,8 @@ class BookmarkTest extends AbstractTestCase
|
||||
$bookmarkData
|
||||
);
|
||||
$this->assertNotFalse($bookmark);
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->assertFalse($bookmark->save());
|
||||
$this->assertAllSelectsConsumed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,10 @@ class ImportControllerTest extends AbstractTestCase
|
||||
|
||||
/** @var ImportController $importController */
|
||||
$importController = $containerBuilder->get(ImportController::class);
|
||||
$this->dummyDbi->addSelectDb('pma_test');
|
||||
$this->dummyDbi->addSelectDb('pma_test');
|
||||
$importController->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$this->assertResponseWasSuccessfull();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
|
||||
@ -146,7 +146,9 @@ class NormalizationControllerTest extends AbstractTestCase
|
||||
$containerBuilder->setParameter('table', $GLOBALS['table']);
|
||||
/** @var NormalizationController $normalizationController */
|
||||
$normalizationController = $containerBuilder->get(NormalizationController::class);
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$normalizationController->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertResponseWasSuccessfull();
|
||||
|
||||
@ -184,7 +186,9 @@ class NormalizationControllerTest extends AbstractTestCase
|
||||
$containerBuilder->setParameter('table', $GLOBALS['table']);
|
||||
/** @var NormalizationController $normalizationController */
|
||||
$normalizationController = $containerBuilder->get(NormalizationController::class);
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$normalizationController->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertResponseWasSuccessfull();
|
||||
|
||||
|
||||
@ -46,7 +46,9 @@ class BinlogControllerTest extends AbstractTestCase
|
||||
|
||||
$_POST['log'] = 'index1';
|
||||
$_POST['pos'] = '3';
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
|
||||
@ -37,7 +37,9 @@ class CollationsControllerTest extends AbstractTestCase
|
||||
|
||||
$controller = new CollationsController($response, new Template(), $GLOBALS['dbi']);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString('<div><strong>latin1</strong></div>', $actual);
|
||||
|
||||
@ -63,7 +63,9 @@ class DatabasesControllerTest extends AbstractTestCase
|
||||
$GLOBALS['dbi']
|
||||
);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString('data-filter-row="SAKILA"', $actual);
|
||||
@ -98,7 +100,9 @@ class DatabasesControllerTest extends AbstractTestCase
|
||||
$_REQUEST['sort_by'] = 'SCHEMA_TABLES';
|
||||
$_REQUEST['sort_order'] = 'desc';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringNotContainsString(__('Enable statistics'), $actual);
|
||||
|
||||
@ -45,7 +45,10 @@ class EnginesControllerTest extends AbstractTestCase
|
||||
|
||||
$controller = new EnginesController($response, new Template(), $dbi);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
@ -94,10 +97,12 @@ class EnginesControllerTest extends AbstractTestCase
|
||||
|
||||
$request = $this->createMock(ServerRequest::class);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->show($request, [
|
||||
'engine' => 'Pbxt',
|
||||
'page' => 'page',
|
||||
]);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
$enginePlugin = StorageEngine::getEngine('Pbxt');
|
||||
|
||||
@ -67,7 +67,9 @@ class PluginsControllerTest extends AbstractTestCase
|
||||
$response = new ResponseRenderer();
|
||||
|
||||
$controller = new PluginsController($response, new Template(), new Plugins($dbi), $GLOBALS['dbi']);
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$actual = $response->getHTMLResult();
|
||||
|
||||
//validate 1:Items
|
||||
|
||||
@ -51,7 +51,9 @@ class MonitorControllerTest extends AbstractTestCase
|
||||
$GLOBALS['dbi']
|
||||
);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
@ -153,7 +155,9 @@ class MonitorControllerTest extends AbstractTestCase
|
||||
$_POST['time_start'] = '0';
|
||||
$_POST['time_end'] = '10';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->logDataTypeSlow();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$ret = $response->getJSONResult();
|
||||
|
||||
$resultRows = [
|
||||
@ -214,7 +218,9 @@ class MonitorControllerTest extends AbstractTestCase
|
||||
$_POST['time_end'] = '10';
|
||||
$_POST['limitTypes'] = '1';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->logDataTypeGeneral();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$ret = $response->getJSONResult();
|
||||
|
||||
$resultRows = [
|
||||
@ -263,7 +269,9 @@ class MonitorControllerTest extends AbstractTestCase
|
||||
|
||||
$_POST['varName'] = 'varName';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->loggingVars();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$ret = $response->getJSONResult();
|
||||
|
||||
$this->assertEquals(
|
||||
@ -299,7 +307,10 @@ class MonitorControllerTest extends AbstractTestCase
|
||||
$_POST['database'] = 'database';
|
||||
$_POST['query'] = 'query';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$this->dummyDbi->addSelectDb('database');
|
||||
$controller->queryAnalyzer();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$ret = $response->getJSONResult();
|
||||
|
||||
$this->assertEquals(
|
||||
|
||||
@ -45,7 +45,9 @@ class ProcessesControllerTest extends AbstractTestCase
|
||||
|
||||
$controller = new ProcessesController($response, new Template(), $this->data, $GLOBALS['dbi']);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
@ -105,7 +107,9 @@ class ProcessesControllerTest extends AbstractTestCase
|
||||
$_POST['order_by_field'] = 'db';
|
||||
$_POST['sort_order'] = 'ASC';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
@ -125,7 +129,9 @@ class ProcessesControllerTest extends AbstractTestCase
|
||||
$_POST['order_by_field'] = 'Host';
|
||||
$_POST['sort_order'] = 'DESC';
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
|
||||
@ -57,7 +57,9 @@ class QueriesControllerTest extends AbstractTestCase
|
||||
|
||||
$controller = new QueriesController($response, new Template(), $this->data, $dbi);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$hourFactor = 3600 / $this->data->status['Uptime'];
|
||||
|
||||
@ -63,7 +63,9 @@ class StatusControllerTest extends AbstractTestCase
|
||||
$replicationInfo->primaryVariables = [];
|
||||
$replicationInfo->replicaVariables = [];
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$traffic = $bytesReceived + $bytesSent;
|
||||
|
||||
@ -41,7 +41,9 @@ class VariablesControllerTest extends AbstractTestCase
|
||||
|
||||
$controller = new VariablesController($response, new Template(), $this->data, $GLOBALS['dbi']);
|
||||
|
||||
$this->dummyDbi->addSelectDb('mysql');
|
||||
$controller->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$html = $response->getHTMLResult();
|
||||
|
||||
$this->assertStringContainsString('<div class="card mb-3" id="tableFilter">', $html);
|
||||
|
||||
@ -96,7 +96,10 @@ class ReplaceControllerTest extends AbstractTestCase
|
||||
$containerBuilder->setParameter('table', $GLOBALS['table']);
|
||||
/** @var ReplaceController $replaceController */
|
||||
$replaceController = $containerBuilder->get(ReplaceController::class);
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$replaceController->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$this->assertStringContainsString(
|
||||
'class="icon ic_s_success"> Showing rows 0 - 1 (2 total, Query took',
|
||||
$this->getResponseHtmlResult()
|
||||
@ -134,7 +137,11 @@ class ReplaceControllerTest extends AbstractTestCase
|
||||
$containerBuilder->setParameter('table', $GLOBALS['table']);
|
||||
/** @var ReplaceController $replaceController */
|
||||
$replaceController = $containerBuilder->get(ReplaceController::class);
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$replaceController->index();
|
||||
$this->assertAllSelectsConsumed();
|
||||
$this->assertEquals(5, $GLOBALS['cfg']['InsertRows']);
|
||||
$this->assertStringContainsString(
|
||||
'<form id="continueForm" method="post" '
|
||||
|
||||
@ -608,7 +608,9 @@ class DatabaseInterfaceTest extends AbstractTestCase
|
||||
['NULL']
|
||||
);
|
||||
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->dbi->initRelationParamsCache();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertArrayHasKey('relation', $_SESSION, 'The cache is expected to be filled');
|
||||
|
||||
@ -716,7 +718,9 @@ class DatabaseInterfaceTest extends AbstractTestCase
|
||||
false
|
||||
);
|
||||
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->dbi->initRelationParamsCache();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertArrayHasKey('relation', $_SESSION, 'The cache is expected to be filled');
|
||||
|
||||
@ -832,7 +836,9 @@ class DatabaseInterfaceTest extends AbstractTestCase
|
||||
['NULL']
|
||||
);
|
||||
|
||||
$this->dummyDbi->addSelectDb('PMA-storage');
|
||||
$this->dbi->initRelationParamsCache();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertArrayNotHasKey(
|
||||
'relation',
|
||||
@ -841,7 +847,10 @@ class DatabaseInterfaceTest extends AbstractTestCase
|
||||
. ' with a default name where found (pma__userconfig vs pma__userconfig_custom)'
|
||||
);
|
||||
|
||||
$this->dummyDbi->addSelectDb('PMA-storage');
|
||||
$relationData = (new Relation($this->dbi))->checkRelationsParam();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertSame([
|
||||
'version' => $relationData['version'],
|
||||
'relwork' => false,
|
||||
|
||||
@ -514,8 +514,12 @@ class ImportTest extends AbstractTestCase
|
||||
'statement' => $parser->statements[0],
|
||||
];
|
||||
|
||||
$this->dummyDbi->addSelectDb('PMA');
|
||||
|
||||
$simulated_data = $this->import->getMatchedRows($analyzed_sql_results);
|
||||
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
// URL to matched rows.
|
||||
$_url_params = [
|
||||
'db' => 'PMA',
|
||||
|
||||
@ -697,6 +697,7 @@ class ExportHtmlwordTest extends AbstractTestCase
|
||||
public function testExportStructure(): void
|
||||
{
|
||||
ob_start();
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -707,6 +708,7 @@ class ExportHtmlwordTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
@ -747,6 +749,7 @@ class ExportHtmlwordTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -757,6 +760,7 @@ class ExportHtmlwordTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
|
||||
@ -594,10 +594,12 @@ class ExportOdtTest extends AbstractTestCase
|
||||
|
||||
public function testGetTableDefStandIn(): void
|
||||
{
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertSame(
|
||||
$this->object->getTableDefStandIn('test_db', 'test_table', "\n"),
|
||||
''
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertEquals(
|
||||
'<table:table table:name="test_table_data">'
|
||||
@ -869,6 +871,7 @@ class ExportOdtTest extends AbstractTestCase
|
||||
public function testExportStructure(): void
|
||||
{
|
||||
// case 1
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -879,6 +882,7 @@ class ExportOdtTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertEquals(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
@ -941,6 +945,7 @@ class ExportOdtTest extends AbstractTestCase
|
||||
// case 3
|
||||
$GLOBALS['odt_buffer'] = '';
|
||||
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -951,6 +956,7 @@ class ExportOdtTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertEquals(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
@ -980,6 +986,7 @@ class ExportOdtTest extends AbstractTestCase
|
||||
);
|
||||
|
||||
// case 4
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$GLOBALS['odt_buffer'] = '';
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
@ -991,6 +998,7 @@ class ExportOdtTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertEquals(
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
|
||||
|
||||
@ -245,7 +245,9 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
|
||||
public function testGetTableDefStandIn(): void
|
||||
{
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$result = $this->object->getTableDefStandIn('test_db', 'test_table', "\n");
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertEquals(
|
||||
'|------' . "\n"
|
||||
@ -396,6 +398,7 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
{
|
||||
// case 1
|
||||
ob_start();
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -406,6 +409,7 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertIsString($result);
|
||||
@ -445,6 +449,7 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
|
||||
// case 3
|
||||
ob_start();
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -455,6 +460,7 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
@ -470,6 +476,7 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
|
||||
// case 4
|
||||
ob_start();
|
||||
$this->dummyDbi->addSelectDb('test_db');
|
||||
$this->assertTrue(
|
||||
$this->object->exportStructure(
|
||||
'test_db',
|
||||
@ -480,6 +487,7 @@ class ExportTexytextTest extends AbstractTestCase
|
||||
'test'
|
||||
)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals(
|
||||
|
||||
@ -78,7 +78,11 @@ class RelationTest extends AbstractTestCase
|
||||
*/
|
||||
public function testPMAGetRelationsParam(): void
|
||||
{
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$relationsPara = $this->relation->getRelationsParam();
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$this->assertFalse(
|
||||
$relationsPara['relwork']
|
||||
);
|
||||
@ -165,12 +169,15 @@ class RelationTest extends AbstractTestCase
|
||||
*/
|
||||
public function testPMAGetDisplayField(): void
|
||||
{
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$db = 'information_schema';
|
||||
$table = 'CHARACTER_SETS';
|
||||
$this->assertEquals(
|
||||
'DESCRIPTION',
|
||||
$this->relation->getDisplayField($db, $table)
|
||||
);
|
||||
$this->assertAllSelectsConsumed();
|
||||
|
||||
$db = 'information_schema';
|
||||
$table = 'TABLES';
|
||||
|
||||
@ -704,7 +704,9 @@ class StorageEngineTest extends AbstractTestCase
|
||||
],
|
||||
]);
|
||||
|
||||
$this->dummyDbi->addSelectDb('my_db');
|
||||
$lengths = StorageEngine::getMroongaLengths('my_db', 'idx_correo');
|
||||
$this->assertAllSelectsConsumed();
|
||||
$this->assertSame([4521984, 578126], $lengths);
|
||||
|
||||
$this->assertAllQueriesConsumed();
|
||||
|
||||
@ -17,17 +17,25 @@ use PhpMyAdmin\FieldMetadata;
|
||||
|
||||
use function addslashes;
|
||||
use function count;
|
||||
use function debug_backtrace;
|
||||
use function fwrite;
|
||||
use function is_array;
|
||||
use function is_bool;
|
||||
use function is_int;
|
||||
use function json_encode;
|
||||
use function preg_replace;
|
||||
use function str_replace;
|
||||
use function trim;
|
||||
|
||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
use const JSON_PRETTY_PRINT;
|
||||
use const JSON_UNESCAPED_SLASHES;
|
||||
use const MYSQLI_TYPE_BLOB;
|
||||
use const MYSQLI_TYPE_DATETIME;
|
||||
use const MYSQLI_TYPE_DECIMAL;
|
||||
use const MYSQLI_TYPE_STRING;
|
||||
use const PHP_EOL;
|
||||
use const STDERR;
|
||||
|
||||
/**
|
||||
* Fake database driver for testing purposes
|
||||
@ -55,6 +63,15 @@ class DbiDummy implements DbiExtension
|
||||
*/
|
||||
private $filoQueries = [];
|
||||
|
||||
/**
|
||||
* First in, last out queries
|
||||
*
|
||||
* The results will be distributed in the fifo way
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $fifoDatabasesToSelect = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @phpstan-var array{
|
||||
@ -101,9 +118,35 @@ class DbiDummy implements DbiExtension
|
||||
*/
|
||||
public function selectDb($databaseName, $link)
|
||||
{
|
||||
$GLOBALS['dummy_db'] = (string) $databaseName;
|
||||
$databaseName = $databaseName instanceof DatabaseName
|
||||
? $databaseName->getName() : $databaseName;
|
||||
|
||||
return true;
|
||||
foreach ($this->fifoDatabasesToSelect as $key => $databaseNameItem) {
|
||||
if ($databaseNameItem !== $databaseName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// It was used
|
||||
unset($this->fifoDatabasesToSelect[$key]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fwrite(STDERR, 'Non expected select of database: ' . $databaseName . PHP_EOL);
|
||||
fwrite(STDERR, 'Trace: ' . json_encode(
|
||||
debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5),
|
||||
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
|
||||
) . PHP_EOL);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUnUsedDatabaseSelects(): array
|
||||
{
|
||||
return $this->fifoDatabasesToSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -498,6 +541,11 @@ class DbiDummy implements DbiExtension
|
||||
return addslashes($string);
|
||||
}
|
||||
|
||||
public function addSelectDb(string $databaseName): void
|
||||
{
|
||||
$this->fifoDatabasesToSelect[] = $databaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds query result for testing
|
||||
*
|
||||
@ -2955,10 +3003,6 @@ class DbiDummy implements DbiExtension
|
||||
],
|
||||
],
|
||||
];
|
||||
/**
|
||||
* Current database.
|
||||
*/
|
||||
$GLOBALS['dummy_db'] = '';
|
||||
|
||||
/* Some basic setup for dummy driver */
|
||||
$GLOBALS['cfg']['DBG']['sql'] = false;
|
||||
|
||||
@ -38,6 +38,11 @@ class TwoFactorTest extends AbstractTestCase
|
||||
$this->initStorageConfigAndData();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->assertAllSelectsConsumed();
|
||||
}
|
||||
|
||||
private function initStorageConfigAndData(): void
|
||||
{
|
||||
$GLOBALS['cfg']['Server']['user'] = 'groot';
|
||||
@ -106,6 +111,7 @@ class TwoFactorTest extends AbstractTestCase
|
||||
$config['settings'] = [];
|
||||
}
|
||||
|
||||
$this->dummyDbi->addSelectDb('phpmyadmin');
|
||||
$this->loadResultForConfig($config);
|
||||
|
||||
return new TwoFactor($user);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user