|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\SqlParser\Tests\Components; |
|
6
|
|
|
|
|
7
|
|
|
use PhpMyAdmin\SqlParser\Components\LockExpression; |
|
8
|
|
|
use PhpMyAdmin\SqlParser\Parser; |
|
9
|
|
|
use PhpMyAdmin\SqlParser\Tests\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class LockExpressionTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testParse(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$component = LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')); |
|
16
|
|
|
$this->assertNotNull($component->table); |
|
17
|
|
|
$this->assertEquals($component->table->table, 'table1'); |
|
18
|
|
|
$this->assertEquals($component->table->alias, 't1'); |
|
19
|
|
|
$this->assertEquals($component->type, 'READ LOCAL'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testParse2(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$component = LockExpression::parse(new Parser(), $this->getTokensList('table1 LOW_PRIORITY WRITE')); |
|
25
|
|
|
$this->assertNotNull($component->table); |
|
26
|
|
|
$this->assertEquals($component->table->table, 'table1'); |
|
27
|
|
|
$this->assertEquals($component->type, 'LOW_PRIORITY WRITE'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @dataProvider parseErrProvider |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testParseErr(string $expr, string $error): void |
|
34
|
|
|
{ |
|
35
|
|
|
$parser = new Parser(); |
|
36
|
|
|
LockExpression::parse($parser, $this->getTokensList($expr)); |
|
37
|
|
|
$errors = $this->getErrorsAsArray($parser); |
|
38
|
|
|
$this->assertEquals($errors[0][0], $error); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return string[][] |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function parseErrProvider(): array |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
[ |
|
48
|
|
|
'table1 AS t1', |
|
49
|
|
|
'Unexpected end of LOCK expression.', |
|
50
|
|
|
], |
|
51
|
|
|
[ |
|
52
|
|
|
'table1 AS t1 READ WRITE', |
|
53
|
|
|
'Unexpected keyword.', |
|
54
|
|
|
], |
|
55
|
|
|
[ |
|
56
|
|
|
'table1 AS t1 READ 2', |
|
57
|
|
|
'Unexpected token.', |
|
58
|
|
|
], |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testBuildAll(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$component = [ |
|
65
|
|
|
LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')), |
|
66
|
|
|
LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')), |
|
67
|
|
|
]; |
|
68
|
|
|
$this->assertEquals( |
|
69
|
|
|
LockExpression::buildAll($component), |
|
70
|
|
|
'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|