* 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,60 +1,62 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
use PhpMyAdmin\SqlParser\Tests\TestCase;
use PhpMyAdmin\SqlParser\UtfString;
use Throwable;
use function chr;
class UtfStringTest extends TestCase
{
/**
* Sample phrase in French.
*
* @var UtfString
*/
public const TEST_PHRASE = 'Les naïfs ægithales hâtifs pondant à Noël où il '
. 'gèle sont sûrs d\'être déçus en voyant leurs drôles d\'œufs abîmés.';
const TEST_PHRASE = 'Les naïfs ægithales hâtifs pondant à Noël où il gèle sont sûrs d\'être déçus en voyant leurs drôles d\'œufs abîmés.';
/**
* The length of the sample phrase.
*
* @var int
*/
public const TEST_PHRASE_LEN = 113;
const TEST_PHRASE_LEN = 113;
public function testArrayAccess(): void
public function testArrayAccess()
{
$str = new UtfString(self::TEST_PHRASE);
$str = new UtfString(static::TEST_PHRASE);
// offsetExists
$this->assertArrayHasKey(self::TEST_PHRASE_LEN - 1, $str);
$this->assertArrayHasKey(static::TEST_PHRASE_LEN - 1, $str);
$this->assertArrayNotHasKey(-1, $str);
$this->assertArrayNotHasKey(self::TEST_PHRASE_LEN, $str);
$this->assertArrayNotHasKey(static::TEST_PHRASE_LEN, $str);
// offsetGet
$this->assertEquals('.', $str[self::TEST_PHRASE_LEN - 1]);
$this->assertEquals('.', $str[static::TEST_PHRASE_LEN - 1]);
$this->assertNull($str[-1]);
$this->assertNull($str[self::TEST_PHRASE_LEN]);
$this->assertNull($str[static::TEST_PHRASE_LEN]);
}
public function testSet(): void
/**
* @expectedException \Exception
* @expectedExceptionMessage Not implemented.
*/
public function testSet()
{
$this->expectExceptionMessage('Not implemented.');
$this->expectException(Throwable::class);
$str = new UtfString('');
$str[0] = 'a';
}
public function testUnset(): void
/**
* @expectedException \Exception
* @expectedExceptionMessage Not implemented.
*/
public function testUnset()
{
$this->expectExceptionMessage('Not implemented.');
$this->expectException(Throwable::class);
$str = new UtfString('');
unset($str[0]);
}
public function testGetCharLength(): void
public function testGetCharLength()
{
$this->assertEquals(1, UtfString::getCharLength(chr(0x00))); // 00000000
$this->assertEquals(1, UtfString::getCharLength(chr(0x7F))); // 01111111
@@ -75,22 +77,22 @@ class UtfStringTest extends TestCase
$this->assertEquals(6, UtfString::getCharLength(chr(0xFD))); // 11111101
}
public function testToString(): void
public function testToString()
{
$str = new UtfString(self::TEST_PHRASE);
$this->assertEquals(self::TEST_PHRASE, (string) $str);
$str = new UtfString(static::TEST_PHRASE);
$this->assertEquals(static::TEST_PHRASE, (string) $str);
}
/**
* Test access to string.
*
* @dataProvider utf8Strings
*
* @param mixed $text
* @param mixed $pos10
* @param mixed $pos20
*
* @dataProvider utf8StringsProvider
*/
public function testAccess($text, $pos10, $pos20): void
public function testAccess($text, $pos10, $pos20)
{
$str = new UtfString($text);
$this->assertEquals($pos10, $str->offsetGet(10));
@@ -98,29 +100,29 @@ class UtfStringTest extends TestCase
$this->assertEquals($pos10, $str->offsetGet(10));
}
public function utf8StringsProvider(): array
public function utf8Strings()
{
return [
'ascii' => [
return array(
'ascii' => array(
'abcdefghijklmnopqrstuvwxyz',
'k',
'u',
],
'unicode' => [
),
'unicode' => array(
'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň',
'ǐ',
'č',
],
'emoji' => [
),
'emoji' => array(
'😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯',
'😂',
'😋',
],
'iso' => [
),
'iso' => array(
"P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy",
null,
null,
],
];
)
);
}
}