CheckControllerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidDatabaseAndTable() 0 18 1
A providerForTestInvalidDatabaseAndTable() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests\Controllers\Table\Partition;
6
7
use PhpMyAdmin\Controllers\Table\Partition\CheckController;
8
use PhpMyAdmin\DatabaseInterface;
9
use PhpMyAdmin\Http\ServerRequest;
10
use PhpMyAdmin\Message;
11
use PhpMyAdmin\Partitioning\Maintenance;
12
use PhpMyAdmin\Tests\AbstractTestCase;
13
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
14
use PHPUnit\Framework\Attributes\CoversClass;
15
use PHPUnit\Framework\Attributes\DataProvider;
16
17
#[CoversClass(CheckController::class)]
18
class CheckControllerTest extends AbstractTestCase
19
{
20
    #[DataProvider('providerForTestInvalidDatabaseAndTable')]
21
    public function testInvalidDatabaseAndTable(
22
        string|null $partition,
23
        string|null $db,
24
        string|null $table,
25
        string $message,
26
    ): void {
27
        $request = self::createStub(ServerRequest::class);
28
        $request->method('getParsedBodyParam')->willReturnMap([['partition_name', null, $partition]]);
29
        $request->method('getParam')->willReturnMap([['db', null, $db], ['table', null, $table]]);
30
        $dbi = $this->createDatabaseInterface();
31
        DatabaseInterface::$instance = $dbi;
32
        $response = new ResponseRenderer();
33
34
        $controller = new CheckController($response, new Maintenance($dbi));
35
        $controller($request);
36
37
        self::assertSame(Message::error($message)->getDisplay(), $response->getHTMLResult());
38
    }
39
40
    /** @return array<int, array{string|null, string|null, string|null, non-empty-string}> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<int, array{string|...ull, non-empty-string}> at position 6 could not be parsed: Expected ':' at position 6, but found 'string'.
Loading history...
41
    public static function providerForTestInvalidDatabaseAndTable(): iterable
42
    {
43
        return [
44
            [null, null, null, 'The partition name must be a non-empty string.'],
45
            ['', null, null, 'The partition name must be a non-empty string.'],
46
            ['partitionName', null, null, 'The database name must be a non-empty string.'],
47
            ['partitionName', '', null, 'The database name must be a non-empty string.'],
48
            ['partitionName', 'databaseName', null, 'The table name must be a non-empty string.'],
49
            ['partitionName', 'databaseName', '', 'The table name must be a non-empty string.'],
50
        ];
51
    }
52
}
53