* Support php 5.3 for sql parser lib.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests\Components;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Components\Expression;
|
||||
@@ -14,7 +12,7 @@ use PhpMyAdmin\SqlParser\Token;
|
||||
|
||||
class KeyTest extends TestCase
|
||||
{
|
||||
public function testParse(): void
|
||||
public function testParse()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -24,14 +22,14 @@ class KeyTest extends TestCase
|
||||
$this->assertNull($component->options);
|
||||
$this->assertNull($component->name);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([], $component->columns);
|
||||
$this->assertSame(array(), $component->columns);
|
||||
$this->assertSame(
|
||||
'()',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithoutOptions(): void
|
||||
public function testParseKeyWithoutOptions()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -41,14 +39,18 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type']], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
)
|
||||
), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `alias_type_idx` (`alias_type`)',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithLengthWithoutOptions(): void
|
||||
public function testParseKeyWithLengthWithoutOptions()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -58,14 +60,19 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type', 'length' => 10]], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
'length' => 10,
|
||||
)
|
||||
), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `alias_type_idx` (`alias_type`(10))',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithLengthWithoutOptionsWithOrder(): void
|
||||
public function testParseKeyWithLengthWithoutOptionsWithOrder()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -75,14 +82,20 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type', 'length' => 10, 'order' => 'ASC']], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
'length' => 10,
|
||||
'order' => 'ASC',
|
||||
)
|
||||
), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `alias_type_idx` (`alias_type`(10) ASC)',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithoutOptionsWithOrderLowercase(): void
|
||||
public function testParseKeyWithoutOptionsWithOrderLowercase()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -92,14 +105,19 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type', 'order' => 'DESC']], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
'order' => 'DESC',
|
||||
)
|
||||
), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `alias_type_idx` (`alias_type` DESC)',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithoutOptionsWithOrder(): void
|
||||
public function testParseKeyWithoutOptionsWithOrder()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -109,14 +127,19 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type', 'order' => 'DESC']], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
'order' => 'DESC',
|
||||
)
|
||||
), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `alias_type_idx` (`alias_type` DESC)',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithLengthWithOptions(): void
|
||||
public function testParseKeyWithLengthWithOptions()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -125,24 +148,29 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(
|
||||
[
|
||||
4 => [
|
||||
array(
|
||||
4 => array(
|
||||
'name' => 'COMMENT',
|
||||
'equals' => false,
|
||||
'expr' => '\'my comment\'',
|
||||
'value' => 'my comment',
|
||||
],
|
||||
]
|
||||
)
|
||||
)
|
||||
), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type', 'length' => 10]], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
'length' => 10,
|
||||
)
|
||||
), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `alias_type_idx` (`alias_type`(10)) COMMENT \'my comment\'',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyWithLengthWithAllOptions(): void
|
||||
public function testParseKeyWithLengthWithAllOptions()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -157,46 +185,51 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('alias_type_idx', $component->name);
|
||||
$this->assertEquals(new OptionsArray(
|
||||
[
|
||||
1 => [
|
||||
array(
|
||||
1 => array(
|
||||
'name' => 'KEY_BLOCK_SIZE',
|
||||
'equals' => true,
|
||||
'expr' => '1',
|
||||
'value' => '1',
|
||||
],
|
||||
2 => [
|
||||
),
|
||||
2 => array(
|
||||
'name' => 'USING',
|
||||
'equals' => false,
|
||||
'expr' => 'BTREE',
|
||||
'value' => 'BTREE',
|
||||
],
|
||||
4 => [
|
||||
),
|
||||
4 => array(
|
||||
'name' => 'COMMENT',
|
||||
'equals' => false,
|
||||
'expr' => '\'my comment\'',
|
||||
'value' => 'my comment',
|
||||
],
|
||||
5 => [
|
||||
),
|
||||
5 => array(
|
||||
'name' => 'ENGINE_ATTRIBUTE',
|
||||
'equals' => true,
|
||||
'expr' => '\'foo\'',
|
||||
'value' => 'foo',
|
||||
],
|
||||
),
|
||||
6 => 'VISIBLE',
|
||||
12 => 'INVISIBLE',
|
||||
13 => [
|
||||
13 => array(
|
||||
'name' => 'SECONDARY_ENGINE_ATTRIBUTE',
|
||||
'equals' => true,
|
||||
'expr' => '\'bar\'',
|
||||
'value' => 'bar',
|
||||
],
|
||||
]
|
||||
),
|
||||
)
|
||||
), $component->options);
|
||||
$this->assertNull($component->expr);
|
||||
$this->assertSame([['name' => 'alias_type', 'length' => 10]], $component->columns);
|
||||
$this->assertSame(array(
|
||||
array(
|
||||
'name' => 'alias_type',
|
||||
'length' => 10,
|
||||
)
|
||||
), $component->columns);
|
||||
}
|
||||
|
||||
public function testParseKeyExpressionWithoutOptions(): void
|
||||
public function testParseKeyExpressionWithoutOptions()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -207,17 +240,22 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('updated_tz_ind2', $component->name);
|
||||
$this->assertEquals(new OptionsArray(), $component->options);
|
||||
$expr = new Expression('(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))');
|
||||
$expr = new Expression(
|
||||
'(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))'
|
||||
);
|
||||
$expr->function = 'convert_tz';
|
||||
$this->assertEquals($expr, $component->expr);
|
||||
$this->assertSame([], $component->columns);
|
||||
$this->assertEquals(
|
||||
$expr,
|
||||
$component->expr
|
||||
);
|
||||
$this->assertSame(array(), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))) ',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyExpressionWithOptions(): void
|
||||
public function testParseKeyExpressionWithOptions()
|
||||
{
|
||||
$component = Key::parse(
|
||||
new Parser(),
|
||||
@@ -230,19 +268,24 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('updated_tz_ind2', $component->name);
|
||||
$this->assertEquals(new OptionsArray(
|
||||
[
|
||||
4 => [
|
||||
array(
|
||||
4 => array(
|
||||
'name' => 'COMMENT',
|
||||
'equals' => false,
|
||||
'expr' => '\'my comment\'',
|
||||
'value' => 'my comment',
|
||||
],
|
||||
]
|
||||
)
|
||||
)
|
||||
), $component->options);
|
||||
$expr = new Expression('(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))');
|
||||
$expr = new Expression(
|
||||
'(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))'
|
||||
);
|
||||
$expr->function = 'convert_tz';
|
||||
$this->assertEquals($expr, $component->expr);
|
||||
$this->assertSame([], $component->columns);
|
||||
$this->assertEquals(
|
||||
$expr,
|
||||
$component->expr
|
||||
);
|
||||
$this->assertSame(array(), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `updated_tz_ind2`'
|
||||
. ' ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')))'
|
||||
@@ -251,7 +294,7 @@ class KeyTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyExpressionWithOptionsError(): void
|
||||
public function testParseKeyExpressionWithOptionsError()
|
||||
{
|
||||
$parser = new Parser();
|
||||
$component = Key::parse(
|
||||
@@ -264,28 +307,38 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('updated_tz_ind2', $component->name);
|
||||
$this->assertEquals(new OptionsArray(
|
||||
[]
|
||||
array(
|
||||
)
|
||||
), $component->options);
|
||||
$t = new Token('convert_tz', Token::TYPE_KEYWORD, 33);
|
||||
$t = new Token(
|
||||
'convert_tz',
|
||||
Token::TYPE_KEYWORD,
|
||||
33
|
||||
);
|
||||
$t->position = 25;
|
||||
|
||||
$this->assertEquals([
|
||||
$this->assertEquals(array(
|
||||
new ParserException(
|
||||
'Unexpected token.',
|
||||
$t
|
||||
),
|
||||
], $parser->errors);
|
||||
$expr = new Expression('(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))');
|
||||
)
|
||||
), $parser->errors);
|
||||
$expr = new Expression(
|
||||
'(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\'))'
|
||||
);
|
||||
$expr->function = 'convert_tz';
|
||||
$this->assertEquals('()(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')', $component->expr);
|
||||
$this->assertSame([], $component->columns);
|
||||
$this->assertEquals(
|
||||
'()(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')',
|
||||
$component->expr
|
||||
);
|
||||
$this->assertSame(array(), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `updated_tz_ind2` (()(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')) ',
|
||||
Key::build($component)
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyOneExpressionWithOptions(): void
|
||||
public function testParseKeyOneExpressionWithOptions()
|
||||
{
|
||||
$parser = new Parser();
|
||||
$component = Key::parse(
|
||||
@@ -302,23 +355,26 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('updated_tz_ind2', $component->name);
|
||||
$this->assertEquals(new OptionsArray(
|
||||
[
|
||||
4 => [
|
||||
array(
|
||||
4 => array(
|
||||
'name' => 'COMMENT',
|
||||
'equals' => false,
|
||||
'expr' => '\'my comment\'',
|
||||
'value' => 'my comment',
|
||||
],
|
||||
]
|
||||
)
|
||||
)
|
||||
), $component->options);
|
||||
$this->assertSame([], $parser->errors);
|
||||
$this->assertSame(array(), $parser->errors);
|
||||
$expr = new Expression(
|
||||
'(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),'
|
||||
. ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\'))'
|
||||
);
|
||||
$expr->function = 'convert_tz';
|
||||
$this->assertEquals($expr, $component->expr);
|
||||
$this->assertSame([], $component->columns);
|
||||
$this->assertEquals(
|
||||
$expr,
|
||||
$component->expr
|
||||
);
|
||||
$this->assertSame(array(), $component->columns);
|
||||
$this->assertSame(
|
||||
'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),'
|
||||
. ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\'))'
|
||||
@@ -327,7 +383,7 @@ class KeyTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseKeyMultipleExpressionsWithOptions(): void
|
||||
public function testParseKeyMultipleExpressionsWithOptions()
|
||||
{
|
||||
$parser = new Parser();
|
||||
$component = Key::parse(
|
||||
@@ -345,14 +401,14 @@ class KeyTest extends TestCase
|
||||
$this->assertEquals('KEY', $component->type);
|
||||
$this->assertEquals('updated_tz_ind2', $component->name);
|
||||
$this->assertEquals(new OptionsArray(
|
||||
[
|
||||
4 => [
|
||||
array(
|
||||
4 => array(
|
||||
'name' => 'COMMENT',
|
||||
'equals' => false,
|
||||
'expr' => '\'my comment\'',
|
||||
'value' => 'my comment',
|
||||
],
|
||||
]
|
||||
)
|
||||
)
|
||||
), $component->options);
|
||||
$expr = new Expression(
|
||||
'(convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),'
|
||||
@@ -360,9 +416,12 @@ class KeyTest extends TestCase
|
||||
. ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'RU\'))'
|
||||
);
|
||||
$expr->function = 'convert_tz';
|
||||
$this->assertEquals($expr, $component->expr);
|
||||
$this->assertSame([], $component->columns);
|
||||
$this->assertSame([], $parser->errors);
|
||||
$this->assertEquals(
|
||||
$expr,
|
||||
$component->expr
|
||||
);
|
||||
$this->assertSame(array(), $component->columns);
|
||||
$this->assertSame(array(), $parser->errors);
|
||||
$this->assertSame(
|
||||
'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'GB\')),'
|
||||
. ' (convert_tz(`cache_updated`,_utf8mb4\'GMT\',_utf8mb4\'FR\')),'
|
||||
|
||||
Reference in New Issue
Block a user