|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\SqlParser\Tests\Utils; |
|
6
|
|
|
|
|
7
|
|
|
use PhpMyAdmin\SqlParser\Lexer; |
|
8
|
|
|
use PhpMyAdmin\SqlParser\Parser; |
|
9
|
|
|
use PhpMyAdmin\SqlParser\Tests\TestCase; |
|
10
|
|
|
use PhpMyAdmin\SqlParser\Utils\Error; |
|
11
|
|
|
|
|
12
|
|
|
class ErrorTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testGet(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$lexer = new Lexer('SELECT * FROM db..tbl }'); |
|
17
|
|
|
$parser = new Parser($lexer->list); |
|
18
|
|
|
$this->assertEquals( |
|
19
|
|
|
[ |
|
20
|
|
|
[ |
|
21
|
|
|
'Unexpected character.', |
|
22
|
|
|
0, |
|
23
|
|
|
'}', |
|
24
|
|
|
22, |
|
25
|
|
|
], |
|
26
|
|
|
[ |
|
27
|
|
|
'Unexpected dot.', |
|
28
|
|
|
0, |
|
29
|
|
|
'.', |
|
30
|
|
|
17, |
|
31
|
|
|
], |
|
32
|
|
|
], |
|
33
|
|
|
Error::get([$lexer, $parser]), |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetWithNullToken(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$lexer = new Lexer('LOCK TABLES table1 AS `t1` LOCAL'); |
|
40
|
|
|
$parser = new Parser($lexer->list); |
|
41
|
|
|
$this->assertSame( |
|
42
|
|
|
[ |
|
43
|
|
|
['An alias was previously found.', 0, 'LOCAL', 27], |
|
44
|
|
|
['Unexpected keyword.', 0, 'LOCAL', 27], |
|
45
|
|
|
['Unexpected end of LOCK expression.', 0, '', null], |
|
46
|
|
|
], |
|
47
|
|
|
Error::get([$lexer, $parser]), |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testFormat(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->assertEquals( |
|
54
|
|
|
['#1: error msg (near "token" at position 100)'], |
|
55
|
|
|
Error::format([['error msg', 42, 'token', 100]]), |
|
56
|
|
|
); |
|
57
|
|
|
$this->assertEquals( |
|
58
|
|
|
[ |
|
59
|
|
|
'#1: error msg (near "token" at position 100)', |
|
60
|
|
|
'#2: error msg (near "token" at position 200)', |
|
61
|
|
|
], |
|
62
|
|
|
Error::format([['error msg', 42, 'token', 100], ['error msg', 42, 'token', 200]]), |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|