phpmyadmin/tests/classes/Controllers/Table/Partition/DropControllerTest.php
Maurício Meneghini Fauth ba72f543fd
Call PHPUnit static methods using static calls
Replaces $this->method() with self::method().

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2024-01-31 17:17:38 -03:00

54 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Table\Partition;
use PhpMyAdmin\Controllers\Table\Partition\DropController;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\Partitioning\Maintenance;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
#[CoversClass(DropController::class)]
class DropControllerTest 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 DropController($response, new Template(), 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.'],
];
}
}