diff --git a/composer.json b/composer.json index 860eaa4..d66f2a1 100644 --- a/composer.json +++ b/composer.json @@ -8,15 +8,16 @@ "email": "wouter@wouterj.nl" } ], - "require": { - "php": "^7.0" + "php": "^8.0" }, - "autoload": { "psr-4": { "WouterJ\\Peg\\": "src/" } }, "autoload-dev": { "psr-4": { "WouterJ\\Peg\\": "tests/" } + }, + "require-dev": { + "phpunit/phpunit": "^9.6" } } diff --git a/src/PegGrammar.php b/src/PegGrammar.php index fa9e821..a924b0a 100644 --- a/src/PegGrammar.php +++ b/src/PegGrammar.php @@ -55,7 +55,7 @@ public function __construct() return $nested[0]; } - return ['choice', array_merge([$nested[0]], array_map('next', $nested[1]))]; + return ['choice', array_merge([$nested[0]], array_map(fn($param) => next($param), $nested[1]))]; }), // Sequence <- Prefix* new Definition('Sequence', ['repeat', ['identifier', 'Prefix']], function ($nested) { @@ -190,7 +190,7 @@ public function __construct() ['identifier', 'Spacing'], ]], ]], function ($nested) { - return ['literal', implode('', array_map('next', $nested[1]))]; + return ['literal', implode('', array_map(fn($param) => next($param), $nested[1]))]; }), // Class <- ’[’ (!’]’ Range)* ’]’ Spacing new Definition('Class', ['sequence', [ diff --git a/tests/GrammarTest.php b/tests/GrammarTest.php index fc7143b..89d639e 100644 --- a/tests/GrammarTest.php +++ b/tests/GrammarTest.php @@ -11,10 +11,12 @@ namespace WouterJ\Peg; +use PHPUnit\Framework\TestCase; + /** * @author Wouter de Jong */ -class GrammarTest extends \PHPUnit_Framework_TestCase +class GrammarTest extends TestCase { public function testPredicates() { diff --git a/tests/ParserTest.php b/tests/ParserTest.php index e44119a..49b965a 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -12,11 +12,12 @@ namespace WouterJ\Peg; use WouterJ\Peg\Exception\DefinitionException; +use PHPUnit\Framework\TestCase; /** * @author Wouter de Jong */ -class ParserTest extends \PHPUnit_Framework_TestCase +class ParserTest extends TestCase { public function testLiteral() { @@ -187,12 +188,11 @@ public function testActions() $this->assertSame(12, $parser->parse('Int', '12')->value()); } - /** - * @expectedException \WouterJ\Peg\Exception\DefinitionException - * @expectedExceptionMessage did you mean one of these `Everything`? - */ public function testUnknownDefinition() { + $this->expectExceptionMessage("did you mean one of these `Everything`?"); + $this->expectException(\WouterJ\Peg\Exception\DefinitionException::class); + $parser = new Parser([ new Definition('Everything', ['any']), new Definition('Digit', ['characterClass', '0-9']), @@ -201,12 +201,11 @@ public function testUnknownDefinition() $parser->parse('Everyting', 'a'); } - /** - * @expectedException \WouterJ\Peg\Exception\DefinitionException - * @expectedExceptionMessageRegExp /^Invalid definition `Foo`: Undefined operator `undefined`\./ - */ public function testInvalidDefinition() { + $this->expectExceptionMessageMatches("/^Invalid definition `Foo`: Undefined operator `undefined`\./"); + $this->expectException(\WouterJ\Peg\Exception\DefinitionException::class); + $parser = new Parser([ new Definition('Mine', ['identifier', 'Custom']), new Definition('Custom', ['identifier', 'Foo']), diff --git a/tests/PegGrammarTest.php b/tests/PegGrammarTest.php index f4e7dfb..313597e 100644 --- a/tests/PegGrammarTest.php +++ b/tests/PegGrammarTest.php @@ -11,10 +11,12 @@ namespace WouterJ\Peg; +use PHPUnit\Framework\TestCase; + /** * @author Wouter de Jong */ -class PegGrammarTest extends \PHPUnit_Framework_TestCase +class PegGrammarTest extends TestCase { /** @dataProvider getGrammars */ public function testGrammar($filePath)