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