2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Tests for Linter.php.
6 * @package PhpMyAdmin-test
8 declare(strict_types
=1);
10 namespace PhpMyAdmin\Tests
;
12 use PhpMyAdmin\Linter
;
13 use PhpMyAdmin\Tests\PmaTestCase
;
16 * Tests for PhpMyAdmin\Linter
18 * @package PhpMyAdmin-test
20 class LinterTest
extends PmaTestCase
23 * Test for Linter::getLines
27 public function testGetLines()
29 $this->assertEquals([0], Linter
::getLines(''));
30 $this->assertEquals([0, 2], Linter
::getLines("a\nb"));
31 $this->assertEquals([0, 4, 7], Linter
::getLines("abc\nde\n"));
35 * Test for Linter::findLineNumberAndColumn
39 public function testFindLineNumberAndColumn()
41 // Let the analyzed string be:
46 // Where `^` is the beginning of the line and `$` the end of the line.
48 // Positions of each character (by line):
49 // ( a, 0), ( b, 1), ( c, 2), (\n, 3),
50 // ( d, 4), ( e, 5), (\n, 6),
57 Linter
::findLineNumberAndColumn([0, 4, 7], 4)
64 Linter
::findLineNumberAndColumn([0, 4, 7], 5)
71 Linter
::findLineNumberAndColumn([0, 4, 7], 6)
78 Linter
::findLineNumberAndColumn([0, 4, 7], 7)
83 * Test for Linter::lint
85 * @dataProvider lintProvider
87 * @param array $expected The expected result.
88 * @param string $query The query to be analyzed.
92 public function testLint($expected, $query): void
94 $this->assertEquals($expected, Linter
::lint($query));
98 * Provides data for `testLint`.
102 public static function lintProvider()
116 'message' => 'Unrecognized data type. (near ' .
122 'severity' => 'error',
125 'message' => 'A closing bracket was expected. (near ' .
131 'severity' => 'error',
134 'CREATE TABLE tbl ( id IN',
139 'message' => 'Linting is disabled for this query because ' .
140 'it exceeds the maximum length.',
145 'severity' => 'warning',
148 str_repeat(";", 10001),