* Update sqlparser to fit php8.

This commit is contained in:
songchenxuan
2024-03-20 09:10:47 +08:00
committed by liyang
parent 380f1d530b
commit f297325727
663 changed files with 140347 additions and 16174 deletions
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
use PhpMyAdmin\SqlParser\Tests\TestCase;
@@ -8,26 +10,40 @@ class BugsTest extends TestCase
{
/**
* @dataProvider bugProvider
*
* @param mixed $test
*/
public function testBug($test)
public function testBug(string $test): void
{
$this->runParserTest($test);
}
public function bugProvider()
/**
* @return string[][]
*/
public function bugProvider(): array
{
return array(
array('bugs/gh9'),
array('bugs/gh14'),
array('bugs/gh16'),
array('bugs/gh317'),
array('bugs/pma11800'),
array('bugs/pma11836'),
array('bugs/pma11843'),
array('bugs/pma11867'),
array('bugs/pma11879')
);
return [
['bugs/fuzz1'],
['bugs/fuzz2'],
['bugs/fuzz3'],
['bugs/fuzz4'],
['bugs/gh9'],
['bugs/gh14'],
['bugs/gh16'],
['bugs/gh202'],
['bugs/gh234'],
['bugs/gh317'],
['bugs/gh412'],
['bugs/gh478'],
['bugs/gh492'],
['bugs/gh496'],
['bugs/gh498'],
['bugs/gh499'],
['bugs/gh508'],
['bugs/gh511'],
['bugs/pma11800'],
['bugs/pma11836'],
['bugs/pma11843'],
['bugs/pma11879'],
];
}
}
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Tests\Misc;
use PhpMyAdmin\SqlParser\Tests\TestCase;
@@ -8,18 +10,20 @@ class ParameterTest extends TestCase
{
/**
* @dataProvider parameterProvider
*
* @param mixed $test
*/
public function testParameter($test)
public function testParameter(string $test): void
{
$this->runParserTest($test);
}
public function parameterProvider()
/**
* @return string[][]
*/
public function parameterProvider(): array
{
return array(
array('misc/parseParameter')
);
return [
['misc/parseParameter'],
['misc/parseParameter2'],
];
}
}
@@ -1,62 +1,60 @@
<?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
*/
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.';
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.';
/**
* The length of the sample phrase.
*
* @var int
*/
const TEST_PHRASE_LEN = 113;
public const TEST_PHRASE_LEN = 113;
public function testArrayAccess()
public function testArrayAccess(): void
{
$str = new UtfString(static::TEST_PHRASE);
$str = new UtfString(self::TEST_PHRASE);
// offsetExists
$this->assertArrayHasKey(static::TEST_PHRASE_LEN - 1, $str);
$this->assertArrayHasKey(self::TEST_PHRASE_LEN - 1, $str);
$this->assertArrayNotHasKey(-1, $str);
$this->assertArrayNotHasKey(static::TEST_PHRASE_LEN, $str);
$this->assertArrayNotHasKey(self::TEST_PHRASE_LEN, $str);
// offsetGet
$this->assertEquals('.', $str[static::TEST_PHRASE_LEN - 1]);
$this->assertEquals('.', $str[self::TEST_PHRASE_LEN - 1]);
$this->assertNull($str[-1]);
$this->assertNull($str[static::TEST_PHRASE_LEN]);
$this->assertNull($str[self::TEST_PHRASE_LEN]);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Not implemented.
*/
public function testSet()
public function testSet(): void
{
$this->expectExceptionMessage('Not implemented.');
$this->expectException(Throwable::class);
$str = new UtfString('');
$str[0] = 'a';
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Not implemented.
*/
public function testUnset()
public function testUnset(): void
{
$this->expectExceptionMessage('Not implemented.');
$this->expectException(Throwable::class);
$str = new UtfString('');
unset($str[0]);
}
public function testGetCharLength()
public function testGetCharLength(): void
{
$this->assertEquals(1, UtfString::getCharLength(chr(0x00))); // 00000000
$this->assertEquals(1, UtfString::getCharLength(chr(0x7F))); // 01111111
@@ -77,22 +75,18 @@ class UtfStringTest extends TestCase
$this->assertEquals(6, UtfString::getCharLength(chr(0xFD))); // 11111101
}
public function testToString()
public function testToString(): void
{
$str = new UtfString(static::TEST_PHRASE);
$this->assertEquals(static::TEST_PHRASE, (string) $str);
$str = new UtfString(self::TEST_PHRASE);
$this->assertEquals(self::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)
public function testAccess(string $text, ?string $pos10, ?string $pos20): void
{
$str = new UtfString($text);
$this->assertEquals($pos10, $str->offsetGet(10));
@@ -100,29 +94,33 @@ class UtfStringTest extends TestCase
$this->assertEquals($pos10, $str->offsetGet(10));
}
public function utf8Strings()
/**
* @return array<string, array<int, string|null>>
* @psalm-return array<string, array{string, (string|null), (string|null)}>
*/
public function utf8StringsProvider(): array
{
return array(
'ascii' => array(
return [
'ascii' => [
'abcdefghijklmnopqrstuvwxyz',
'k',
'u',
),
'unicode' => array(
],
'unicode' => [
'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň',
'ǐ',
'č',
),
'emoji' => array(
],
'emoji' => [
'😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯',
'😂',
'😋',
),
'iso' => array(
],
'iso' => [
"P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy",
null,
null,
)
);
],
];
}
}