diff --git a/Tests/ExpressionLanguageTest.php b/Tests/ExpressionLanguageTest.php index e8ecfc5..efd58cf 100644 --- a/Tests/ExpressionLanguageTest.php +++ b/Tests/ExpressionLanguageTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\ExpressionLanguage\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; @@ -71,9 +72,7 @@ public function testCachedParse() $this->assertSame($savedParsedExpression, $parsedExpression); } - /** - * @dataProvider basicPhpFunctionProvider - */ + #[DataProvider('basicPhpFunctionProvider')] public function testBasicPhpFunction($expression, $expected, $compiled) { $expressionLanguage = new ExpressionLanguage(); @@ -137,9 +136,7 @@ public function testCompiledEnumFunctionWithBackedEnum() $this->assertSame(FooBackedEnum::Bar, $result); } - /** - * @dataProvider providerTestCases - */ + #[DataProvider('providerTestCases')] public function testProviders(iterable $providers) { $expressionLanguage = new ExpressionLanguage(null, $providers); @@ -161,18 +158,14 @@ public static function providerTestCases(): iterable })()]; } - /** - * @dataProvider shortCircuitProviderEvaluate - */ + #[DataProvider('shortCircuitProviderEvaluate')] public function testShortCircuitOperatorsEvaluate($expression, array $values, $expected) { $expressionLanguage = new ExpressionLanguage(); $this->assertSame($expected, $expressionLanguage->evaluate($expression, $values)); } - /** - * @dataProvider shortCircuitProviderCompile - */ + #[DataProvider('shortCircuitProviderCompile')] public function testShortCircuitOperatorsCompile($expression, array $names, $expected) { $result = null; @@ -304,9 +297,7 @@ public function testOperatorCollisions() $this->assertTrue($result); } - /** - * @dataProvider getRegisterCallbacks - */ + #[DataProvider('getRegisterCallbacks')] public function testRegisterAfterParse($registerCallback) { $this->expectException(\LogicException::class); @@ -315,9 +306,7 @@ public function testRegisterAfterParse($registerCallback) $registerCallback($el); } - /** - * @dataProvider getRegisterCallbacks - */ + #[DataProvider('getRegisterCallbacks')] public function testRegisterAfterEval($registerCallback) { $this->expectException(\LogicException::class); @@ -326,18 +315,14 @@ public function testRegisterAfterEval($registerCallback) $registerCallback($el); } - /** - * @dataProvider provideNullSafe - */ + #[DataProvider('provideNullSafe')] public function testNullSafeEvaluate($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); $this->assertNull($expressionLanguage->evaluate($expression, ['foo' => $foo])); } - /** - * @dataProvider provideNullSafe - */ + #[DataProvider('provideNullSafe')] public function testNullSafeCompile($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); @@ -374,9 +359,7 @@ public function bar() yield ['foo?.bar()["baz"]["qux"].quux()', null]; } - /** - * @dataProvider provideInvalidNullSafe - */ + #[DataProvider('provideInvalidNullSafe')] public function testNullSafeEvaluateFails($expression, $foo, $message) { $expressionLanguage = new ExpressionLanguage(); @@ -386,10 +369,8 @@ public function testNullSafeEvaluateFails($expression, $foo, $message) $expressionLanguage->evaluate($expression, ['foo' => $foo]); } - /** - * @dataProvider provideInvalidNullSafe - */ - public function testNullSafeCompileFails($expression, $foo) + #[DataProvider('provideInvalidNullSafe')] + public function testNullSafeCompileFails($expression, $foo, $message) { $expressionLanguage = new ExpressionLanguage(); @@ -417,18 +398,14 @@ public static function provideInvalidNullSafe() yield ['foo?.bar["baz"].qux.quux', (object) ['bar' => ['baz' => null]], 'Unable to get property "qux" of non-object "foo?.bar["baz"]".']; } - /** - * @dataProvider provideNullCoalescing - */ + #[DataProvider('provideNullCoalescing')] public function testNullCoalescingEvaluate($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); $this->assertSame($expressionLanguage->evaluate($expression, ['foo' => $foo]), 'default'); } - /** - * @dataProvider provideNullCoalescing - */ + #[DataProvider('provideNullCoalescing')] public function testNullCoalescingCompile($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); @@ -459,9 +436,7 @@ public function bar() yield ['foo[123][456][789] ?? "default"', [123 => []]]; } - /** - * @dataProvider getRegisterCallbacks - */ + #[DataProvider('getRegisterCallbacks')] public function testRegisterAfterCompile($registerCallback) { $this->expectException(\LogicException::class); @@ -478,9 +453,7 @@ public static function validCommentProvider() yield ["/* multi\nline */ 'foo'"]; } - /** - * @dataProvider validCommentProvider - */ + #[DataProvider('validCommentProvider')] public function testLintAllowsComments($expression) { $el = new ExpressionLanguage(); @@ -496,9 +469,7 @@ public static function invalidCommentProvider() yield ['1 /* double closing */ */']; } - /** - * @dataProvider invalidCommentProvider - */ + #[DataProvider('invalidCommentProvider')] public function testLintThrowsOnInvalidComments($expression) { $el = new ExpressionLanguage(); diff --git a/Tests/LexerTest.php b/Tests/LexerTest.php index 2827cf6..c05b3a4 100644 --- a/Tests/LexerTest.php +++ b/Tests/LexerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\ExpressionLanguage\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\ExpressionLanguage\Lexer; use Symfony\Component\ExpressionLanguage\SyntaxError; @@ -26,9 +27,7 @@ protected function setUp(): void $this->lexer = new Lexer(); } - /** - * @dataProvider getTokenizeData - */ + #[DataProvider('getTokenizeData')] public function testTokenize($tokens, $expression) { $tokens[] = new Token('end of expression', null, \strlen($expression) + 1); diff --git a/Tests/Node/AbstractNodeTestCase.php b/Tests/Node/AbstractNodeTestCase.php index 7521788..0fc70e7 100644 --- a/Tests/Node/AbstractNodeTestCase.php +++ b/Tests/Node/AbstractNodeTestCase.php @@ -11,14 +11,13 @@ namespace Symfony\Component\ExpressionLanguage\Tests\Node; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\ExpressionLanguage\Compiler; abstract class AbstractNodeTestCase extends TestCase { - /** - * @dataProvider getEvaluateData - */ + #[DataProvider('getEvaluateData')] public function testEvaluate($expected, $node, $variables = [], $functions = []) { $this->assertSame($expected, $node->evaluate($functions, $variables)); @@ -26,9 +25,7 @@ public function testEvaluate($expected, $node, $variables = [], $functions = []) abstract public static function getEvaluateData(); - /** - * @dataProvider getCompileData - */ + #[DataProvider('getCompileData')] public function testCompile($expected, $node, $functions = []) { $compiler = new Compiler($functions); @@ -38,9 +35,7 @@ public function testCompile($expected, $node, $functions = []) abstract public static function getCompileData(); - /** - * @dataProvider getDumpData - */ + #[DataProvider('getDumpData')] public function testDump($expected, $node) { $this->assertSame($expected, $node->dump()); diff --git a/Tests/Node/ArgumentsNodeTest.php b/Tests/Node/ArgumentsNodeTest.php index 2b25073..d059949 100644 --- a/Tests/Node/ArgumentsNodeTest.php +++ b/Tests/Node/ArgumentsNodeTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\ExpressionLanguage\Tests\Node; use Symfony\Component\ExpressionLanguage\Node\ArgumentsNode; +use Symfony\Component\ExpressionLanguage\Node\ArrayNode; class ArgumentsNodeTest extends ArrayNodeTest { @@ -29,7 +30,7 @@ public static function getDumpData(): \Generator ]; } - protected static function createArrayNode(): \Symfony\Component\ExpressionLanguage\Node\ArrayNode + protected static function createArrayNode(): ArrayNode { return new ArgumentsNode(); } diff --git a/Tests/Node/BinaryNodeTest.php b/Tests/Node/BinaryNodeTest.php index 375d0a1..592e84d 100644 --- a/Tests/Node/BinaryNodeTest.php +++ b/Tests/Node/BinaryNodeTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\ExpressionLanguage\Tests\Node; +use PHPUnit\Framework\Attributes\TestWith; use Symfony\Component\ExpressionLanguage\Compiler; use Symfony\Component\ExpressionLanguage\Node\ArrayNode; use Symfony\Component\ExpressionLanguage\Node\BinaryNode; @@ -265,10 +266,8 @@ public function testModuloByZero() $node->evaluate([], []); } - /** - * @testWith [1] - * ["true"] - */ + #[TestWith([1])] + #[TestWith(['true'])] public function testInOperatorStrictness(mixed $value) { $array = new ArrayNode(); diff --git a/Tests/Node/NodeTest.php b/Tests/Node/NodeTest.php index 44f8bd7..f8975d4 100644 --- a/Tests/Node/NodeTest.php +++ b/Tests/Node/NodeTest.php @@ -23,11 +23,12 @@ public function testToString() $node = new Node([new ConstantNode('foo')]); $this->assertEquals(<<<'EOF' -Node( - ConstantNode(value: 'foo') -) -EOF - , (string) $node); + Node( + ConstantNode(value: 'foo') + ) + EOF, + (string) $node + ); } public function testSerialization() diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index 0f1c893..aaf9fe6 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\ExpressionLanguage\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\ExpressionLanguage\Lexer; use Symfony\Component\ExpressionLanguage\Node; @@ -59,9 +60,7 @@ public function testParseUnknownFunction() $parser->parse($tokenized); } - /** - * @dataProvider getParseData - */ + #[DataProvider('getParseData')] public function testParse($node, $expression, $names = []) { $lexer = new Lexer(); @@ -269,9 +268,7 @@ private static function createGetAttrNode($node, $item, $type) return new Node\GetAttrNode($node, new Node\ConstantNode($item, Node\GetAttrNode::ARRAY_CALL !== $type), new Node\ArgumentsNode(), $type); } - /** - * @dataProvider getInvalidPostfixData - */ + #[DataProvider('getInvalidPostfixData')] public function testParseWithInvalidPostfixData($expr, $names = []) { $this->expectException(SyntaxError::class); @@ -312,9 +309,7 @@ public function testNameProposal() $parser->parse($lexer->tokenize('foo > bar'), ['foo', 'baz']); } - /** - * @dataProvider getLintData - */ + #[DataProvider('getLintData')] public function testLint($expression, $names, int $checks = 0, ?string $exception = null) { if ($exception) { @@ -326,7 +321,7 @@ public function testLint($expression, $names, int $checks = 0, ?string $exceptio $parser = new Parser([]); $parser->lint($lexer->tokenize($expression), $names, $checks); - // Parser does't return anything when the correct expression is passed + // Parser doesn't return anything when the correct expression is passed $this->expectNotToPerformAssertions(); } diff --git a/composer.json b/composer.json index e24a315..e3989cd 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=8.2", - "symfony/cache": "^6.4|^7.0", + "symfony/cache": "^6.4|^7.0|^8.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^2.5|^3" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8e60a89..bf5d7ef 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + +