* Support php 5.3 for sql parser lib.

This commit is contained in:
qixinzhi
2023-02-10 11:24:24 +08:00
parent 7c2e937eda
commit 7c122a0b29
648 changed files with 13815 additions and 279048 deletions
@@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Components;
use PhpMyAdmin\SqlParser\Components\OptionsArray;
@@ -10,69 +8,69 @@ use PhpMyAdmin\SqlParser\Tests\TestCase;
class OptionsArrayTest extends TestCase
{
public function testParse(): void
public function testParse()
{
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
[
array(
'A' => 1,
'B' => [
'B' => array(
2,
'var',
],
'C' => 3,
]
),
'C' => 3
)
);
$this->assertEquals(
[
array(
1 => 'A',
2 => [
2 => array(
'name' => 'B',
'expr' => '(test)',
'value' => 'test',
'equals' => true,
],
),
3 => 'C',
],
),
$component->options
);
}
public function testParseExpr(): void
public function testParseExpr()
{
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('SUM = (3 + 5) RESULT = 8'),
[
'SUM' => [
array(
'SUM' => array(
1,
'expr',
['parenthesesDelimited' => true],
],
'RESULT' => [
array('parenthesesDelimited' => true),
),
'RESULT' => array(
2,
'var',
],
]
)
)
);
$this->assertEquals('(3 + 5)', (string) $component->has('SUM', true));
$this->assertEquals('8', $component->has('RESULT'));
}
public function testHas(): void
public function testHas()
{
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
[
array(
'A' => 1,
'B' => [
'B' => array(
2,
'var',
],
'C' => 3,
]
),
'C' => 3
)
);
$this->assertTrue($component->has('A'));
$this->assertEquals('test', $component->has('B'));
@@ -80,51 +78,51 @@ class OptionsArrayTest extends TestCase
$this->assertFalse($component->has('D'));
}
public function testRemove(): void
public function testRemove()
{
/* Assertion 1 */
$component = new OptionsArray(['a', 'b', 'c']);
$component = new OptionsArray(array('a', 'b', 'c'));
$this->assertTrue($component->remove('b'));
$this->assertFalse($component->remove('d'));
$this->assertEquals($component->options, [0 => 'a', 2 => 'c']);
$this->assertEquals($component->options, array(0 => 'a', 2 => 'c'));
/* Assertion 2 */
$component = OptionsArray::parse(
new Parser(),
$this->getTokensList('A B = /*comment*/ (test) C'),
[
array(
'A' => 1,
'B' => [
'B' => array(
2,
'var',
],
'C' => 3,
]
),
'C' => 3
)
);
$this->assertEquals('test', $component->has('B'));
$component->remove('B');
$this->assertFalse($component->has('B'));
}
public function testMerge(): void
public function testMerge()
{
$component = new OptionsArray(['a']);
$component->merge(['b', 'c']);
$this->assertEquals($component->options, ['a', 'b', 'c']);
$component = new OptionsArray(array('a'));
$component->merge(array('b', 'c'));
$this->assertEquals($component->options, array('a', 'b', 'c'));
}
public function testBuild(): void
public function testBuild()
{
$component = new OptionsArray(
[
array(
'ALL',
'SQL_CALC_FOUND_ROWS',
[
array(
'name' => 'MAX_STATEMENT_TIME',
'value' => '42',
'equals' => true,
],
]
),
)
);
$this->assertEquals(
OptionsArray::build($component),