3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PHPUnit\Framework\Attributes\CoversClass
;
9 use PHPUnit\Framework\Attributes\DataProvider
;
11 use function str_repeat
;
13 #[CoversClass(Linter::class)]
14 class LinterTest
extends AbstractTestCase
17 * Sets up the fixture, for example, opens a network connection.
18 * This method is called before a test is executed.
20 protected function setUp(): void
28 * Test for Linter::getLines
30 public function testGetLines(): void
32 self
::assertSame([0], Linter
::getLines(''));
33 self
::assertSame([0, 2], Linter
::getLines("a\nb"));
34 self
::assertSame([0, 4, 7], Linter
::getLines("abc\nde\n"));
38 * Test for Linter::findLineNumberAndColumn
40 public function testFindLineNumberAndColumn(): void
42 // Let the analyzed string be:
47 // Where `^` is the beginning of the line and `$` the end of the line.
49 // Positions of each character (by line):
50 // ( a, 0), ( b, 1), ( c, 2), (\n, 3),
51 // ( d, 4), ( e, 5), (\n, 6),
55 Linter
::findLineNumberAndColumn([0, 4, 7], 4),
59 Linter
::findLineNumberAndColumn([0, 4, 7], 5),
63 Linter
::findLineNumberAndColumn([0, 4, 7], 6),
67 Linter
::findLineNumberAndColumn([0, 4, 7], 7),
72 * Test for Linter::lint
74 * @param mixed[] $expected The expected result.
75 * @param string $query The query to be analyzed.
77 #[DataProvider('lintProvider')]
78 public function testLint(array $expected, string $query): void
80 self
::assertSame($expected, Linter
::lint($query));
84 * Provides data for `testLint`.
86 * @return array<array{mixed[], string}>
88 public static function lintProvider(): array
92 [[], 'SELECT * FROM tbl'],
96 'message' => 'Unrecognized data type. (near <code>IN</code>)',
101 'severity' => 'error',
104 'message' => 'A closing bracket was expected. (near <code>IN</code>)',
109 'severity' => 'error',
112 'CREATE TABLE tbl ( id IN',
117 'message' => 'Linting is disabled for this query because it exceeds the maximum length.',
122 'severity' => 'warning',
125 str_repeat(';', 10001),