Skip to content

Commit 6521c15

Browse files
authored
Upgrade to phpunit 9 (#350)
* upgrade phpunit to version 9.5 so tests can be run with php 8.1 (the test suite does not run yet, need to adapt some phpunit code, and address some php deprecations, see following commits) * phpunit upgrade: adapt test case class name phpunit's classes are now namespaced * phpunit upgrade: `setUp` must match its parent's signature * phpunit upgrade: avoid risky tests label for tests that do not perform any assertions * avoid polluting the phpunit output * phpunit upgrade: `@expectedException` is not available anymore * php 8.1 deprecation: `preg_split`'s `$limit` param should be an int * php 8.1 deprecation: Automatic conversion of false to array is deprecated * php 8.1 deprecation: Automatic conversion of false to array is deprecated * php 8.1 deprecation: Automatic conversion of false to array is deprecated * php 8.1 deprecation: Automatic conversion of false to array is deprecated
1 parent e38d6f0 commit 6521c15

175 files changed

Lines changed: 205 additions & 190 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"require-dev" : {
4343
"squizlabs/php_codesniffer" : "^1.5.1",
44-
"phpunit/phpunit" : "^4.0.14",
44+
"phpunit/phpunit" : "^9.5.13",
4545
"analog/analog" : "^1.0.6"
4646
}
4747
}

src/PHPSQLParser/lexer/PHPSQLLexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function split($sql) {
8484
if (!is_string($sql)) {
8585
throw new InvalidParameterException($sql);
8686
}
87-
$tokens = preg_split($this->splitters->getSplittersRegexPattern(), $sql, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
87+
$tokens = preg_split($this->splitters->getSplittersRegexPattern(), $sql, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
8888
$tokens = $this->concatComments($tokens);
8989
$tokens = $this->concatEscapeSequences($tokens);
9090
$tokens = $this->balanceBackticks($tokens);

src/PHPSQLParser/processors/FromProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ protected function initParseInfo($parseInfo = false) {
7676
}
7777
// loop init
7878
return array('expression' => "", 'token_count' => 0, 'table' => "", 'no_quotes' => "", 'alias' => false,
79-
'hints' => false, 'join_type' => "", 'next_join_type' => "",
79+
'hints' => array(), 'join_type' => "", 'next_join_type' => "",
8080
'saved_join_type' => $parseInfo['saved_join_type'], 'ref_type' => false, 'ref_expr' => false,
8181
'base_expr' => false, 'sub_tree' => false, 'subquery' => "");
8282
}
8383

8484
protected function processFromExpression(&$parseInfo) {
8585
$res = array();
8686

87+
if ($parseInfo['hints'] === array()) {
88+
$parseInfo['hints'] = false;
89+
}
90+
8791
// exchange the join types (join_type is save now, saved_join_type holds the next one)
8892
$parseInfo['join_type'] = $parseInfo['saved_join_type']; // initialized with JOIN
8993
$parseInfo['saved_join_type'] = ($parseInfo['next_join_type'] ? $parseInfo['next_join_type'] : 'JOIN');

src/PHPSQLParser/processors/IndexProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function process($tokens) {
7272

7373
$currCategory = 'INDEX_NAME';
7474
$result = array('base_expr' => false, 'name' => false, 'no_quotes' => false, 'index-type' => false, 'on' => false,
75-
'options' => false);
75+
'options' => array());
7676
$expr = array();
7777
$base_expr = '';
7878
$skip = 0;
@@ -300,6 +300,9 @@ public function process($tokens) {
300300
$currCategory = '';
301301
}
302302

303+
if ($result['options'] === array()) {
304+
$result['options'] = false;
305+
}
303306
return $result;
304307
}
305308
}

src/PHPSQLParser/processors/SQLProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function process($tokens) {
5959
$prev_category = "";
6060
$token_category = "";
6161
$skip_next = 0;
62-
$out = false;
62+
$out = array();
6363

6464
// $tokens may come as a numeric indexed array starting with an index greater than 0 (or as a boolean)
6565
$tokenCount = count($tokens);

src/PHPSQLParser/processors/TableProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function process($tokens) {
8383

8484
$currCategory = 'TABLE_NAME';
8585
$result = array('base_expr' => false, 'name' => false, 'no_quotes' => false, 'create-def' => false,
86-
'options' => false, 'like' => false, 'select-option' => false);
86+
'options' => array(), 'like' => false, 'select-option' => false);
8787
$expr = array();
8888
$base_expr = '';
8989
$skip = 0;
@@ -366,6 +366,9 @@ public function process($tokens) {
366366
if ($result['select-option'] === false) {
367367
unset($result['select-option']);
368368
}
369+
if ($result['options'] === array()) {
370+
$result['options'] = false;
371+
}
369372

370373
return $result;
371374
}

tests/cases/AbstractTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHPSQLParser\PHPSQLCreator;
66
use Analog\Analog;
77

8-
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase {
8+
abstract class AbstractTestCase extends \PHPUnit\Framework\TestCase {
99

1010
protected $parser;
1111
protected $creator;
@@ -22,7 +22,7 @@ protected function logSerialized($message) {
2222
* @before
2323
* Executed before each test
2424
*/
25-
protected function setup() {
25+
protected function setup(): void {
2626
$this->parser = new PHPSQLParser();
2727
$this->creator = new PHPSQLCreator();
2828
}

tests/cases/creator/AlterTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
use PHPSQLParser\PHPSQLParser;
55
use PHPSQLParser\PHPSQLCreator;
6-
use PHPUnit_Framework_TestCase;
76

8-
class AlterTest extends PHPUnit_Framework_TestCase
7+
class AlterTest extends \PHPUnit\Framework\TestCase
98
{
109
public function testAlterChangeColumn()
1110
{

tests/cases/creator/ascTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
use PHPSQLParser\PHPSQLParser;
4343
use PHPSQLParser\PHPSQLCreator;
4444

45-
class ascTest extends \PHPUnit_Framework_TestCase {
45+
class ascTest extends \PHPUnit\Framework\TestCase {
4646

4747
public function testAsc() {
4848
$sql = "SELECT qid FROM QUESTIONS WHERE gid='1' and language='de-informal' ORDER BY question_order, title ASC";

tests/cases/creator/count_distinctTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
use PHPSQLParser\PHPSQLParser;
4343
use PHPSQLParser\PHPSQLCreator;
4444

45-
class count_distinctTest extends \PHPUnit_Framework_TestCase {
45+
class count_distinctTest extends \PHPUnit\Framework\TestCase {
4646

4747
public function testCount_distinct() {
4848

0 commit comments

Comments
 (0)