Skip to content

Commit

Permalink
Updated tests to pass with PHP 8.3, also updated minimum PHP version …
Browse files Browse the repository at this point in the history
…to 8.
  • Loading branch information
smuuf committed Oct 13, 2024
1 parent dbf646a commit 40ac5ca
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 45 deletions.
2 changes: 1 addition & 1 deletion bin/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

cd $(dirname $0)

../vendor/bin/phpstan analyze --level=5 ../lib $@
../vendor/bin/phpstan analyze -c ../phpstan.neon $@

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
],
"require": {
"php": ">=7.4"
"php": ">=8.0"
},
"autoload": {
"psr-0": {
Expand Down
45 changes: 22 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/hafriedlander/Peg/Compiler/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function tokenize($str, &$tokens, $o = 0) {
}
/* Handle expression labels */
elseif (\preg_match('/\G(\w*):/', $str, $match, 0, $o)) {
$pending->set('tag', $match[1] ?? '');
$pending->set('tag', $match[1] ?: '');
$o += \strlen($match[0]);
}
/* Handle descent token */
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 5
paths:
- ./lib
- ./tests
8 changes: 5 additions & 3 deletions tests/CachedRegexp.phpt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

use \Tester\Assert;
declare(strict_types=1);

use \hafriedlander\Peg\Parser\Basic;
use \hafriedlander\Peg\Parser\CachedRegexp;
use Tester\Assert;

use hafriedlander\Peg\Parser\Basic;
use hafriedlander\Peg\Parser\CachedRegexp;

require __DIR__ . '/bootstrap.php';

Expand Down
4 changes: 3 additions & 1 deletion tests/ParserInheritance.phpt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use \Tester\Assert;
declare(strict_types=1);

use Tester\Assert;

require __DIR__ . '/bootstrap.php';

Expand Down
6 changes: 5 additions & 1 deletion tests/ParserPackrat.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

declare(strict_types=1);

use hafriedlander\Peg\Parser\Packrat;

require __DIR__ . '/bootstrap.php';

class ParserPackratTest extends ParserTestBase {
Expand All @@ -22,7 +26,7 @@ class ParserPackratTest extends ParserTestBase {
Expression: Add
*/
', 'Packrat');
', Packrat::class);

$parser->assertMatches('Expression', '1 + 2 * 3 + 4 + 4 + 4 + 4 + 4 / 5 - 6 + 7 * 8 - 9');
$parser->assertDoesntMatch('Expression', 'variables + do + not + exist');
Expand Down
2 changes: 2 additions & 0 deletions tests/ParserSyntax.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require __DIR__ . '/bootstrap.php';

class ParserSyntaxTest extends ParserTestBase {
Expand Down
20 changes: 11 additions & 9 deletions tests/ParserVariables.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require __DIR__ . '/bootstrap.php';

class ParserVariablesTest extends ParserTestBase {
Expand All @@ -25,15 +27,15 @@ class ParserVariablesTest extends ParserTestBase {
public function testRecurseOnVariables() {

$parser = $this->buildParser('
/*!* RecurseOnVariablesParser
A: "a"
B: "b"
Foo: $Template
Bar: Foo
function __construct(&$res){ $res["Template"] = "A"; }
Baz: Foo
function __construct(&$res){ $res["Template"] = "B"; }
*/
/*!* RecurseOnVariablesParser
A: "a"
B: "b"
Foo: $Template
Bar: Foo
function __construct(&$res){ $res["Template"] = "A"; }
Baz: Foo
function __construct(&$res){ $res["Template"] = "B"; }
*/
');

$parser->assertMatches('Bar', 'a');
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/bootstrap.utils.php';

Expand Down
21 changes: 16 additions & 5 deletions tests/bootstrap.utils.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

use \Tester\Assert;
use \Tester\TestCase;
declare(strict_types=1);

use \hafriedlander\Peg;
use Tester\Assert;
use Tester\TestCase;

use hafriedlander\Peg;
use hafriedlander\Peg\Parser\Basic;

class ParserTestWrapper {

/**
* @var class-string<Basic>
*/
private string $parserClass;

function __construct(string $parserClass) {
$this->parserClass = $parserClass;
}
Expand Down Expand Up @@ -59,11 +67,14 @@ function assertDoesntMatch($method, $string, $message = null) {

class ParserTestBase extends TestCase {

function buildParser($grammar, $baseClass = 'Basic') {
function buildParser(
string $grammar,
string $baseClass = Basic::class,
): ParserTestWrapper {

$class = 'Parser_' . md5(uniqid());
eval(Peg\Compiler::compile("
class $class extends hafriedlander\Peg\Parser\\$baseClass {
class $class extends $baseClass {
$grammar
}
"));
Expand Down

0 comments on commit 40ac5ca

Please sign in to comment.