phpmyadmin/test/classes/Controllers/Table/Partition/CheckControllerTest.php
Maurício Meneghini Fauth 4ff3724c3f
Use union with null instead of short nullable type
Since union type are now possible, using union with null makes more
clear that it is a union type.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-02-20 21:48:19 -03:00

57 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers\Table\Partition;
use PhpMyAdmin\Controllers\Table\Partition\CheckController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\Partitioning\Maintenance;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
/**
* @covers \PhpMyAdmin\Controllers\Table\Partition\CheckController
*/
class CheckControllerTest extends AbstractTestCase
{
/**
* @dataProvider providerForTestInvalidDatabaseAndTable
*/
public function testInvalidDatabaseAndTable(
string|null $partition,
string|null $db,
string|null $table,
string $message
): void {
$request = $this->createStub(ServerRequest::class);
$request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]);
$request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]);
$dbi = $this->createDatabaseInterface();
$GLOBALS['dbi'] = $dbi;
$response = new ResponseRenderer();
$controller = new CheckController($response, new Template(), new Maintenance($dbi));
$controller($request);
$this->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.'],
];
}
}