phpmyadmin/tests/unit/Controllers/Table/Partition/AnalyzeControllerTest.php
Kamil Tekiela 8015e4de72 Move DatabaseInterface to Dbal
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2024-12-22 18:34:53 +00:00

53 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Table\Partition;
use PhpMyAdmin\Controllers\Table\Partition\AnalyzeController;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\Partitioning\Maintenance;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
#[CoversClass(AnalyzeController::class)]
class AnalyzeControllerTest extends AbstractTestCase
{
#[DataProvider('providerForTestInvalidDatabaseAndTable')]
public function testInvalidDatabaseAndTable(
string|null $partition,
string|null $db,
string|null $table,
string $message,
): void {
$request = self::createStub(ServerRequest::class);
$request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]);
$request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]);
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
$response = new ResponseRenderer();
$controller = new AnalyzeController($response, new Maintenance($dbi));
$controller($request);
self::assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult());
}
/** @return array<int, array{string|null, string|null, string|null, non-empty-string}> */
public static function providerForTestInvalidDatabaseAndTable(): iterable
{
return [
[null, null, null, 'The partition name must be a non-empty string.'],
['', null, null, 'The partition name must be a non-empty string.'],
['partitionName', null, null, 'The database name must be a non-empty string.'],
['partitionName', '', null, 'The database name must be a non-empty string.'],
['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'],
['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'],
];
}
}