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 72
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
use PhpMyAdmin\SqlParser\Components\LockExpression;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class LockExpressionTest extends TestCase
{
public function testParse(): void
{
$component = LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL'));
$this->assertNotNull($component->table);
$this->assertEquals($component->table->table, 'table1');
$this->assertEquals($component->table->alias, 't1');
$this->assertEquals($component->type, 'READ LOCAL');
}
public function testParse2(): void
{
$component = LockExpression::parse(new Parser(), $this->getTokensList('table1 LOW_PRIORITY WRITE'));
$this->assertNotNull($component->table);
$this->assertEquals($component->table->table, 'table1');
$this->assertEquals($component->type, 'LOW_PRIORITY WRITE');
}
#[DataProvider('parseErrProvider')]
public function testParseErr(string $expr, string $error): void
{
$parser = new Parser();
LockExpression::parse($parser, $this->getTokensList($expr));
$errors = $this->getErrorsAsArray($parser);
$this->assertEquals($errors[0][0], $error);
}
/**
* @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 testBuild(): void
{
$component = [
LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')),
LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')),
];
$this->assertEquals(
LockExpression::build($component),
'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE'
);
}
}
|