From 8531e287762f41d39d07823346ed8683f3822f10 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 15 Jan 2023 18:57:26 +0100 Subject: [PATCH 1/9] [Tests] New iteration of removing `$this` occurrences in future static data providers --- Tests/Node/AbstractNodeTest.php | 6 ++--- Tests/Node/ArgumentsNodeTest.php | 12 +++++----- Tests/Node/ArrayNodeTest.php | 22 ++++++++--------- Tests/Node/BinaryNodeTest.php | 6 ++--- Tests/Node/ConditionalNodeTest.php | 6 ++--- Tests/Node/ConstantNodeTest.php | 6 ++--- Tests/Node/FunctionNodeTest.php | 14 +++++------ Tests/Node/GetAttrNodeTest.php | 38 +++++++++++++++--------------- Tests/Node/NameNodeTest.php | 6 ++--- Tests/Node/UnaryNodeTest.php | 6 ++--- 10 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Tests/Node/AbstractNodeTest.php b/Tests/Node/AbstractNodeTest.php index 2975037..81625c5 100644 --- a/Tests/Node/AbstractNodeTest.php +++ b/Tests/Node/AbstractNodeTest.php @@ -24,7 +24,7 @@ public function testEvaluate($expected, $node, $variables = [], $functions = []) $this->assertSame($expected, $node->evaluate($functions, $variables)); } - abstract public function getEvaluateData(); + abstract public static function getEvaluateData(); /** * @dataProvider getCompileData @@ -36,7 +36,7 @@ public function testCompile($expected, $node, $functions = []) $this->assertSame($expected, $compiler->getSource()); } - abstract public function getCompileData(); + abstract public static function getCompileData(); /** * @dataProvider getDumpData @@ -46,5 +46,5 @@ public function testDump($expected, $node) $this->assertSame($expected, $node->dump()); } - abstract public function getDumpData(); + abstract public static function getDumpData(); } diff --git a/Tests/Node/ArgumentsNodeTest.php b/Tests/Node/ArgumentsNodeTest.php index 9d88b4a..2b25073 100644 --- a/Tests/Node/ArgumentsNodeTest.php +++ b/Tests/Node/ArgumentsNodeTest.php @@ -15,21 +15,21 @@ class ArgumentsNodeTest extends ArrayNodeTest { - public function getCompileData() + public static function getCompileData(): array { return [ - ['"a", "b"', $this->getArrayNode()], + ['"a", "b"', static::getArrayNode()], ]; } - public function getDumpData() + public static function getDumpData(): \Generator { - return [ - ['"a", "b"', $this->getArrayNode()], + yield from [ + ['"a", "b"', static::getArrayNode()], ]; } - protected function createArrayNode() + protected static function createArrayNode(): \Symfony\Component\ExpressionLanguage\Node\ArrayNode { return new ArgumentsNode(); } diff --git a/Tests/Node/ArrayNodeTest.php b/Tests/Node/ArrayNodeTest.php index 3d03d83..db06513 100644 --- a/Tests/Node/ArrayNodeTest.php +++ b/Tests/Node/ArrayNodeTest.php @@ -28,45 +28,45 @@ public function testSerialization() $this->assertNotEquals($this->createArrayNode(), $unserializedNode); } - public function getEvaluateData() + public static function getEvaluateData(): array { return [ - [['b' => 'a', 'b'], $this->getArrayNode()], + [['b' => 'a', 'b'], static::getArrayNode()], ]; } - public function getCompileData() + public static function getCompileData(): array { return [ - ['["b" => "a", 0 => "b"]', $this->getArrayNode()], + ['["b" => "a", 0 => "b"]', static::getArrayNode()], ]; } - public function getDumpData() + public static function getDumpData(): \Generator { - yield ['{"b": "a", 0: "b"}', $this->getArrayNode()]; + yield ['{"b": "a", 0: "b"}', static::getArrayNode()]; - $array = $this->createArrayNode(); + $array = static::createArrayNode(); $array->addElement(new ConstantNode('c'), new ConstantNode('a"b')); $array->addElement(new ConstantNode('d'), new ConstantNode('a\b')); yield ['{"a\\"b": "c", "a\\\\b": "d"}', $array]; - $array = $this->createArrayNode(); + $array = static::createArrayNode(); $array->addElement(new ConstantNode('c')); $array->addElement(new ConstantNode('d')); yield ['["c", "d"]', $array]; } - protected function getArrayNode() + protected static function getArrayNode(): ArrayNode { - $array = $this->createArrayNode(); + $array = static::createArrayNode(); $array->addElement(new ConstantNode('a'), new ConstantNode('b')); $array->addElement(new ConstantNode('b')); return $array; } - protected function createArrayNode() + protected static function createArrayNode(): ArrayNode { return new ArrayNode(); } diff --git a/Tests/Node/BinaryNodeTest.php b/Tests/Node/BinaryNodeTest.php index fe3115a..af9e5fc 100644 --- a/Tests/Node/BinaryNodeTest.php +++ b/Tests/Node/BinaryNodeTest.php @@ -20,7 +20,7 @@ class BinaryNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { $array = new ArrayNode(); $array->addElement(new ConstantNode('a')); @@ -71,7 +71,7 @@ public function getEvaluateData() ]; } - public function getCompileData() + public static function getCompileData(): array { $array = new ArrayNode(); $array->addElement(new ConstantNode('a')); @@ -120,7 +120,7 @@ public function getCompileData() ]; } - public function getDumpData() + public static function getDumpData(): array { $array = new ArrayNode(); $array->addElement(new ConstantNode('a')); diff --git a/Tests/Node/ConditionalNodeTest.php b/Tests/Node/ConditionalNodeTest.php index 13b7cbd..497b6d0 100644 --- a/Tests/Node/ConditionalNodeTest.php +++ b/Tests/Node/ConditionalNodeTest.php @@ -16,7 +16,7 @@ class ConditionalNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { return [ [1, new ConditionalNode(new ConstantNode(true), new ConstantNode(1), new ConstantNode(2))], @@ -24,7 +24,7 @@ public function getEvaluateData() ]; } - public function getCompileData() + public static function getCompileData(): array { return [ ['((true) ? (1) : (2))', new ConditionalNode(new ConstantNode(true), new ConstantNode(1), new ConstantNode(2))], @@ -32,7 +32,7 @@ public function getCompileData() ]; } - public function getDumpData() + public static function getDumpData(): array { return [ ['(true ? 1 : 2)', new ConditionalNode(new ConstantNode(true), new ConstantNode(1), new ConstantNode(2))], diff --git a/Tests/Node/ConstantNodeTest.php b/Tests/Node/ConstantNodeTest.php index fee9f5b..2d0a55e 100644 --- a/Tests/Node/ConstantNodeTest.php +++ b/Tests/Node/ConstantNodeTest.php @@ -15,7 +15,7 @@ class ConstantNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { return [ [false, new ConstantNode(false)], @@ -28,7 +28,7 @@ public function getEvaluateData() ]; } - public function getCompileData() + public static function getCompileData(): array { return [ ['false', new ConstantNode(false)], @@ -41,7 +41,7 @@ public function getCompileData() ]; } - public function getDumpData() + public static function getDumpData(): array { return [ ['false', new ConstantNode(false)], diff --git a/Tests/Node/FunctionNodeTest.php b/Tests/Node/FunctionNodeTest.php index c6cb02c..18ec21f 100644 --- a/Tests/Node/FunctionNodeTest.php +++ b/Tests/Node/FunctionNodeTest.php @@ -17,28 +17,28 @@ class FunctionNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { return [ - ['bar', new FunctionNode('foo', new Node([new ConstantNode('bar')])), [], ['foo' => $this->getCallables()]], + ['bar', new FunctionNode('foo', new Node([new ConstantNode('bar')])), [], ['foo' => static::getCallables()]], ]; } - public function getCompileData() + public static function getCompileData(): array { return [ - ['foo("bar")', new FunctionNode('foo', new Node([new ConstantNode('bar')])), ['foo' => $this->getCallables()]], + ['foo("bar")', new FunctionNode('foo', new Node([new ConstantNode('bar')])), ['foo' => static::getCallables()]], ]; } - public function getDumpData() + public static function getDumpData(): array { return [ - ['foo("bar")', new FunctionNode('foo', new Node([new ConstantNode('bar')])), ['foo' => $this->getCallables()]], + ['foo("bar")', new FunctionNode('foo', new Node([new ConstantNode('bar')])), ['foo' => static::getCallables()]], ]; } - protected function getCallables() + protected static function getCallables(): array { return [ 'compiler' => function ($arg) { diff --git a/Tests/Node/GetAttrNodeTest.php b/Tests/Node/GetAttrNodeTest.php index c790f33..15cbe05 100644 --- a/Tests/Node/GetAttrNodeTest.php +++ b/Tests/Node/GetAttrNodeTest.php @@ -18,46 +18,46 @@ class GetAttrNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { return [ - ['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], - ['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], + ['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], + ['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], - ['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']], + ['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']], ]; } - public function getCompileData() + public static function getCompileData(): array { return [ - ['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], ]; } - public function getDumpData() + public static function getDumpData(): array { return [ - ['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), $this->getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), $this->getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), $this->getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], ]; } - protected function getArrayNode() + protected static function getArrayNode(): ArrayNode { $array = new ArrayNode(); $array->addElement(new ConstantNode('a'), new ConstantNode('b')); diff --git a/Tests/Node/NameNodeTest.php b/Tests/Node/NameNodeTest.php index a30c27b..f0f60d1 100644 --- a/Tests/Node/NameNodeTest.php +++ b/Tests/Node/NameNodeTest.php @@ -15,21 +15,21 @@ class NameNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { return [ ['bar', new NameNode('foo'), ['foo' => 'bar']], ]; } - public function getCompileData() + public static function getCompileData(): array { return [ ['$foo', new NameNode('foo')], ]; } - public function getDumpData() + public static function getDumpData(): array { return [ ['foo', new NameNode('foo')], diff --git a/Tests/Node/UnaryNodeTest.php b/Tests/Node/UnaryNodeTest.php index bac75d2..bb7cea5 100644 --- a/Tests/Node/UnaryNodeTest.php +++ b/Tests/Node/UnaryNodeTest.php @@ -16,7 +16,7 @@ class UnaryNodeTest extends AbstractNodeTest { - public function getEvaluateData() + public static function getEvaluateData(): array { return [ [-1, new UnaryNode('-', new ConstantNode(1))], @@ -26,7 +26,7 @@ public function getEvaluateData() ]; } - public function getCompileData() + public static function getCompileData(): array { return [ ['(-1)', new UnaryNode('-', new ConstantNode(1))], @@ -36,7 +36,7 @@ public function getCompileData() ]; } - public function getDumpData() + public static function getDumpData(): array { return [ ['(- 1)', new UnaryNode('-', new ConstantNode(1))], From 0e748125d62fa926f6f19db23e9b7771d709a58a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 2/9] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 0083704..0138f8f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 49aba92ba2c7e9362e70227caf28eefd65acd589 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 5 Feb 2023 10:12:16 +0100 Subject: [PATCH 3/9] [Tests] Migrate data providers to static ones --- Tests/ParserTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/ParserTest.php b/Tests/ParserTest.php index 3cec3e2..d98091a 100644 --- a/Tests/ParserTest.php +++ b/Tests/ParserTest.php @@ -47,7 +47,7 @@ public function testParse($node, $expression, $names = []) $this->assertEquals($node, $parser->parse($lexer->tokenize($expression), $names)); } - public function getParseData() + public static function getParseData() { $arguments = new Node\ArgumentsNode(); $arguments->addElement(new Node\ConstantNode('arg1')); @@ -139,10 +139,10 @@ public function getParseData() // chained calls [ - $this->createGetAttrNode( - $this->createGetAttrNode( - $this->createGetAttrNode( - $this->createGetAttrNode(new Node\NameNode('foo'), 'bar', Node\GetAttrNode::METHOD_CALL), + self::createGetAttrNode( + self::createGetAttrNode( + self::createGetAttrNode( + self::createGetAttrNode(new Node\NameNode('foo'), 'bar', Node\GetAttrNode::METHOD_CALL), 'foo', Node\GetAttrNode::METHOD_CALL), 'baz', Node\GetAttrNode::PROPERTY_CALL), '3', Node\GetAttrNode::ARRAY_CALL), @@ -192,7 +192,7 @@ public function getParseData() ]; } - private function createGetAttrNode($node, $item, $type) + 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); } @@ -208,7 +208,7 @@ public function testParseWithInvalidPostfixData($expr, $names = []) $parser->parse($lexer->tokenize($expr), $names); } - public function getInvalidPostfixData() + public static function getInvalidPostfixData() { return [ [ @@ -258,7 +258,7 @@ public function testLint($expression, $names, string $exception = null) $this->expectNotToPerformAssertions(); } - public function getLintData(): array + public static function getLintData(): array { return [ 'valid expression' => [ From 4f83c13b8e7d7e42fd49af099bfe5af9ff9abb54 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Feb 2023 10:31:13 +0100 Subject: [PATCH 4/9] minor #49253 [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` (OskarStark) This PR was merged into the 6.3 branch. Discussion ---------- [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Refs https://github.com/symfony/symfony/pull/49233 | License | MIT | Doc PR | n/a Replaces #49234 Using `Test` suffix is deprecated since PHPUnit 10 Spotted in * https://github.com/symfony/symfony/pull/49233 Commits ------- cb3db968e4 [PHPUnit 10] Use `TestCase` suffix for abstract tests in `/Tests/` --- Tests/Node/{AbstractNodeTest.php => AbstractNodeTestCase.php} | 2 +- Tests/Node/ArrayNodeTest.php | 2 +- Tests/Node/BinaryNodeTest.php | 2 +- Tests/Node/ConditionalNodeTest.php | 2 +- Tests/Node/ConstantNodeTest.php | 2 +- Tests/Node/FunctionNodeTest.php | 2 +- Tests/Node/GetAttrNodeTest.php | 2 +- Tests/Node/NameNodeTest.php | 2 +- Tests/Node/UnaryNodeTest.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename Tests/Node/{AbstractNodeTest.php => AbstractNodeTestCase.php} (95%) diff --git a/Tests/Node/AbstractNodeTest.php b/Tests/Node/AbstractNodeTestCase.php similarity index 95% rename from Tests/Node/AbstractNodeTest.php rename to Tests/Node/AbstractNodeTestCase.php index 81625c5..7521788 100644 --- a/Tests/Node/AbstractNodeTest.php +++ b/Tests/Node/AbstractNodeTestCase.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\ExpressionLanguage\Compiler; -abstract class AbstractNodeTest extends TestCase +abstract class AbstractNodeTestCase extends TestCase { /** * @dataProvider getEvaluateData diff --git a/Tests/Node/ArrayNodeTest.php b/Tests/Node/ArrayNodeTest.php index db06513..fcd7636 100644 --- a/Tests/Node/ArrayNodeTest.php +++ b/Tests/Node/ArrayNodeTest.php @@ -14,7 +14,7 @@ use Symfony\Component\ExpressionLanguage\Node\ArrayNode; use Symfony\Component\ExpressionLanguage\Node\ConstantNode; -class ArrayNodeTest extends AbstractNodeTest +class ArrayNodeTest extends AbstractNodeTestCase { public function testSerialization() { diff --git a/Tests/Node/BinaryNodeTest.php b/Tests/Node/BinaryNodeTest.php index af9e5fc..a44a685 100644 --- a/Tests/Node/BinaryNodeTest.php +++ b/Tests/Node/BinaryNodeTest.php @@ -18,7 +18,7 @@ use Symfony\Component\ExpressionLanguage\Node\NameNode; use Symfony\Component\ExpressionLanguage\SyntaxError; -class BinaryNodeTest extends AbstractNodeTest +class BinaryNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { diff --git a/Tests/Node/ConditionalNodeTest.php b/Tests/Node/ConditionalNodeTest.php index 497b6d0..4555429 100644 --- a/Tests/Node/ConditionalNodeTest.php +++ b/Tests/Node/ConditionalNodeTest.php @@ -14,7 +14,7 @@ use Symfony\Component\ExpressionLanguage\Node\ConditionalNode; use Symfony\Component\ExpressionLanguage\Node\ConstantNode; -class ConditionalNodeTest extends AbstractNodeTest +class ConditionalNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { diff --git a/Tests/Node/ConstantNodeTest.php b/Tests/Node/ConstantNodeTest.php index 2d0a55e..f1b1004 100644 --- a/Tests/Node/ConstantNodeTest.php +++ b/Tests/Node/ConstantNodeTest.php @@ -13,7 +13,7 @@ use Symfony\Component\ExpressionLanguage\Node\ConstantNode; -class ConstantNodeTest extends AbstractNodeTest +class ConstantNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { diff --git a/Tests/Node/FunctionNodeTest.php b/Tests/Node/FunctionNodeTest.php index 18ec21f..2ae6f95 100644 --- a/Tests/Node/FunctionNodeTest.php +++ b/Tests/Node/FunctionNodeTest.php @@ -15,7 +15,7 @@ use Symfony\Component\ExpressionLanguage\Node\FunctionNode; use Symfony\Component\ExpressionLanguage\Node\Node; -class FunctionNodeTest extends AbstractNodeTest +class FunctionNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { diff --git a/Tests/Node/GetAttrNodeTest.php b/Tests/Node/GetAttrNodeTest.php index 15cbe05..df8ecea 100644 --- a/Tests/Node/GetAttrNodeTest.php +++ b/Tests/Node/GetAttrNodeTest.php @@ -16,7 +16,7 @@ use Symfony\Component\ExpressionLanguage\Node\GetAttrNode; use Symfony\Component\ExpressionLanguage\Node\NameNode; -class GetAttrNodeTest extends AbstractNodeTest +class GetAttrNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { diff --git a/Tests/Node/NameNodeTest.php b/Tests/Node/NameNodeTest.php index f0f60d1..661466f 100644 --- a/Tests/Node/NameNodeTest.php +++ b/Tests/Node/NameNodeTest.php @@ -13,7 +13,7 @@ use Symfony\Component\ExpressionLanguage\Node\NameNode; -class NameNodeTest extends AbstractNodeTest +class NameNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { diff --git a/Tests/Node/UnaryNodeTest.php b/Tests/Node/UnaryNodeTest.php index bb7cea5..7da4be7 100644 --- a/Tests/Node/UnaryNodeTest.php +++ b/Tests/Node/UnaryNodeTest.php @@ -14,7 +14,7 @@ use Symfony\Component\ExpressionLanguage\Node\ConstantNode; use Symfony\Component\ExpressionLanguage\Node\UnaryNode; -class UnaryNodeTest extends AbstractNodeTest +class UnaryNodeTest extends AbstractNodeTestCase { public static function getEvaluateData(): array { From f8b0188f22910e8b8336293fc897c015d92cd4bd Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 7 Feb 2023 21:09:05 +0100 Subject: [PATCH 5/9] [Tests] Migrate tests to static data providers --- Tests/Node/GetAttrNodeTest.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Tests/Node/GetAttrNodeTest.php b/Tests/Node/GetAttrNodeTest.php index df8ecea..6d81a2b 100644 --- a/Tests/Node/GetAttrNodeTest.php +++ b/Tests/Node/GetAttrNodeTest.php @@ -21,39 +21,39 @@ class GetAttrNodeTest extends AbstractNodeTestCase public static function getEvaluateData(): array { return [ - ['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], - ['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], + ['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], + ['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], - ['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']], + ['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']], ]; } public static function getCompileData(): array { return [ - ['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], ]; } public static function getDumpData(): array { return [ - ['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], ]; } From 4684d53c499b1c6b6de08ef9e8c7f320eca0f055 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sat, 11 Feb 2023 19:34:13 +0100 Subject: [PATCH 6/9] Fix some phpdoc --- Token.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Token.php b/Token.php index 8399f70..3df869f 100644 --- a/Token.php +++ b/Token.php @@ -32,7 +32,7 @@ class Token /** * @param string $type The type of the token (self::*_TYPE) * @param string|int|float|null $value The token value - * @param int $cursor The cursor position in the source + * @param int|null $cursor The cursor position in the source */ public function __construct(string $type, $value, ?int $cursor) { From 501589522b844b8eecf012c133f0404f0eef77ac Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 7/9] Migrate to `static` data providers using `rector/rector` --- Tests/ExpressionLanguageTest.php | 6 +++--- Tests/LexerTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/ExpressionLanguageTest.php b/Tests/ExpressionLanguageTest.php index c4c98dd..309472c 100644 --- a/Tests/ExpressionLanguageTest.php +++ b/Tests/ExpressionLanguageTest.php @@ -119,7 +119,7 @@ public function testParseThrowsInsteadOfNotice() $expressionLanguage->parse('node.', ['node']); } - public function shortCircuitProviderEvaluate() + public static function shortCircuitProviderEvaluate() { $object = new class(\Closure::fromCallable([static::class, 'fail'])) { private $fail; @@ -143,7 +143,7 @@ public function foo() ]; } - public function shortCircuitProviderCompile() + public static function shortCircuitProviderCompile() { return [ ['false and foo', ['foo' => 'foo'], false], @@ -267,7 +267,7 @@ public function testRegisterAfterCompile($registerCallback) $registerCallback($el); } - public function getRegisterCallbacks() + public static function getRegisterCallbacks() { return [ [ diff --git a/Tests/LexerTest.php b/Tests/LexerTest.php index 67e551f..8441e52 100644 --- a/Tests/LexerTest.php +++ b/Tests/LexerTest.php @@ -54,7 +54,7 @@ public function testTokenizeThrowsErrorOnUnclosedBrace() $this->lexer->tokenize($expression); } - public function getTokenizeData() + public static function getTokenizeData() { return [ [ From 4a1ff08390f498ae1ccf1e7662bec804b85b7cca Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 14 Feb 2023 23:28:43 +0100 Subject: [PATCH 8/9] Fix PHPUnit 9.6 deprecations --- Tests/ExpressionLanguageTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Tests/ExpressionLanguageTest.php b/Tests/ExpressionLanguageTest.php index 3daaf63..e0cfeef 100644 --- a/Tests/ExpressionLanguageTest.php +++ b/Tests/ExpressionLanguageTest.php @@ -311,12 +311,25 @@ public function testNullSafeEvaluateFails($expression, $foo, $message) /** * @dataProvider provideInvalidNullSafe */ - public function testNullSafeCompileFails($expression, $foo) + public function testNullSafeCompileFails($expression) { $expressionLanguage = new ExpressionLanguage(); - $this->expectWarning(); - eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo']))); + $this->expectException(\ErrorException::class); + + set_error_handler(static function (int $errno, string $errstr, string $errfile = null, int $errline = null): bool { + if ($errno & (\E_WARNING | \E_USER_WARNING)) { + throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); + } + + return false; + }); + + try { + eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo']))); + } finally { + restore_error_handler(); + } } public static function provideInvalidNullSafe() From 13cfebf680eb793b618b7f5647da67d8f36bdafe Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 15 Feb 2023 14:50:43 +0100 Subject: [PATCH 9/9] add missing variable --- Tests/ExpressionLanguageTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ExpressionLanguageTest.php b/Tests/ExpressionLanguageTest.php index e0cfeef..0f8f96e 100644 --- a/Tests/ExpressionLanguageTest.php +++ b/Tests/ExpressionLanguageTest.php @@ -311,14 +311,14 @@ public function testNullSafeEvaluateFails($expression, $foo, $message) /** * @dataProvider provideInvalidNullSafe */ - public function testNullSafeCompileFails($expression) + public function testNullSafeCompileFails($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); $this->expectException(\ErrorException::class); set_error_handler(static function (int $errno, string $errstr, string $errfile = null, int $errline = null): bool { - if ($errno & (\E_WARNING | \E_USER_WARNING)) { + if ($errno & (\E_WARNING | \E_USER_WARNING) && (str_contains($errstr, 'Attempt to read property') || str_contains($errstr, 'Trying to access'))) { throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); }