phpmyadmin/test/classes/Controllers/Server/Status/Monitor/SlowLogControllerTest.php
Maurício Meneghini Fauth dd885dc7b8
Use single-line arrays when possible
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-03-27 17:39:17 -03:00

77 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Server\Status\Monitor;
use PhpMyAdmin\Controllers\Server\Status\Monitor\SlowLogController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Server\Status\Data;
use PhpMyAdmin\Server\Status\Monitor;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
/** @covers \PhpMyAdmin\Controllers\Server\Status\Monitor\SlowLogController */
class SlowLogControllerTest extends AbstractTestCase
{
protected DatabaseInterface $dbi;
protected DbiDummy $dummyDbi;
private Data $data;
protected function setUp(): void
{
parent::setUp();
$GLOBALS['text_dir'] = 'ltr';
parent::setGlobalConfig();
parent::setTheme();
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
$GLOBALS['dbi'] = $this->dbi;
$GLOBALS['server'] = 1;
$GLOBALS['db'] = 'db';
$GLOBALS['table'] = 'table';
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$this->data = new Data($this->dbi, $GLOBALS['config']);
}
public function testSlowLog(): void
{
$response = new ResponseRenderer();
$response->setAjax(true);
$controller = new SlowLogController(
$response,
new Template(),
$this->data,
new Monitor($GLOBALS['dbi']),
$GLOBALS['dbi'],
);
$request = $this->createStub(ServerRequest::class);
$request->method('getParsedBodyParam')->willReturnMap([['time_start', null, '0'], ['time_end', null, '10']]);
$this->dummyDbi->addSelectDb('mysql');
$controller($request);
$this->dummyDbi->assertAllSelectsConsumed();
$ret = $response->getJSONResult();
$resultRows = [['sql_text' => 'insert sql_text', '#' => 11], ['sql_text' => 'update sql_text', '#' => 10]];
$resultSum = ['insert' => 11, 'TOTAL' => 21, 'update' => 10];
$this->assertEquals(2, $ret['message']['numRows']);
$this->assertEquals($resultRows, $ret['message']['rows']);
$this->assertEquals($resultSum, $ret['message']['sum']);
}
}