* Support php 5.3 for sql parser lib.
This commit is contained in:
+22
-39
@@ -1,41 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Bootstrap for tests.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\SqlParser\Tests;
|
||||
|
||||
use PhpMyAdmin\SqlParser\Context;
|
||||
use PhpMyAdmin\SqlParser\Exceptions\LexerException;
|
||||
use PhpMyAdmin\SqlParser\Exceptions\ParserException;
|
||||
use PhpMyAdmin\SqlParser\Lexer;
|
||||
use PhpMyAdmin\SqlParser\Parser;
|
||||
use PhpMyAdmin\SqlParser\TokensList;
|
||||
use PhpMyAdmin\SqlParser\Context;
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
use Zumba\JsonSerializer\JsonSerializer;
|
||||
|
||||
use function file_get_contents;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
$GLOBALS['lang'] = 'en';
|
||||
|
||||
/**
|
||||
* Implements useful methods for testing.
|
||||
*
|
||||
* @category Tests
|
||||
*
|
||||
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
|
||||
*/
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
global $lang;
|
||||
// This line makes sure the test suite uses English so we can assert
|
||||
// on the error messages, if it is not here you will need to use
|
||||
// LC_ALL=C ./vendor/bin/phpunit
|
||||
// Users can have French language as default on their OS
|
||||
// That would make the assertions fail
|
||||
$lang = 'en';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the token list generated by lexing this query.
|
||||
*
|
||||
@@ -59,21 +46,20 @@ abstract class TestCase extends BaseTestCase
|
||||
*/
|
||||
public function getErrorsAsArray($obj)
|
||||
{
|
||||
$ret = [];
|
||||
/** @var LexerException|ParserException $err */
|
||||
$ret = array();
|
||||
foreach ($obj->errors as $err) {
|
||||
$ret[] = $obj instanceof Lexer
|
||||
? [
|
||||
? array(
|
||||
$err->getMessage(),
|
||||
$err->ch,
|
||||
$err->pos,
|
||||
$err->getCode(),
|
||||
]
|
||||
: [
|
||||
)
|
||||
: array(
|
||||
$err->getMessage(),
|
||||
$err->token,
|
||||
$err->getCode(),
|
||||
];
|
||||
$err->getCode()
|
||||
);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -88,8 +74,12 @@ abstract class TestCase extends BaseTestCase
|
||||
*/
|
||||
public function getData($name)
|
||||
{
|
||||
$serializer = new JsonSerializer();
|
||||
$data = $serializer->unserialize((string) file_get_contents('tests/data/' . $name . '.out'));
|
||||
/*
|
||||
* The unrestricted unserialize() is needed here as we do have
|
||||
* serialized objects in the tests. There should be no security risk as
|
||||
* the test data comes with the repository.
|
||||
*/
|
||||
$data = unserialize(file_get_contents('tests/data/' . $name . '.out'));
|
||||
$data['query'] = file_get_contents('tests/data/' . $name . '.in');
|
||||
|
||||
return $data;
|
||||
@@ -114,24 +104,17 @@ abstract class TestCase extends BaseTestCase
|
||||
Context::setMode('ANSI_QUOTES');
|
||||
}
|
||||
|
||||
$mariaDbPos = strpos($name, '_mariadb_');
|
||||
if ($mariaDbPos !== false) {// Keep in sync with TestGenerator.php
|
||||
// set context
|
||||
$mariaDbVersion = (int) substr($name, $mariaDbPos + 9, 6);
|
||||
Context::load('MariaDb' . $mariaDbVersion);
|
||||
}
|
||||
|
||||
// Lexer.
|
||||
$lexer = new Lexer($data['query']);
|
||||
$lexerErrors = $this->getErrorsAsArray($lexer);
|
||||
$lexer->errors = [];
|
||||
$lexer->errors = array();
|
||||
|
||||
// Parser.
|
||||
$parser = empty($data['parser']) ? null : new Parser($lexer->list);
|
||||
$parserErrors = [];
|
||||
$parserErrors = array();
|
||||
if ($parser !== null) {
|
||||
$parserErrors = $this->getErrorsAsArray($parser);
|
||||
$parser->errors = [];
|
||||
$parser->errors = array();
|
||||
}
|
||||
|
||||
// Testing objects.
|
||||
|
||||
Reference in New Issue
Block a user