Skip to content

Commit be9035a

Browse files
committed
replace PHPUnit annotations with attributes
1 parent b3f60d6 commit be9035a

File tree

5 files changed

+29
-70
lines changed

5 files changed

+29
-70
lines changed

Tests/ExpressionLanguageTest.php

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\ExpressionLanguage\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Psr\Cache\CacheItemInterface;
1617
use Psr\Cache\CacheItemPoolInterface;
@@ -71,9 +72,7 @@ public function testCachedParse()
7172
$this->assertSame($savedParsedExpression, $parsedExpression);
7273
}
7374

74-
/**
75-
* @dataProvider basicPhpFunctionProvider
76-
*/
75+
#[DataProvider('basicPhpFunctionProvider')]
7776
public function testBasicPhpFunction($expression, $expected, $compiled)
7877
{
7978
$expressionLanguage = new ExpressionLanguage();
@@ -137,9 +136,7 @@ public function testCompiledEnumFunctionWithBackedEnum()
137136
$this->assertSame(FooBackedEnum::Bar, $result);
138137
}
139138

140-
/**
141-
* @dataProvider providerTestCases
142-
*/
139+
#[DataProvider('providerTestCases')]
143140
public function testProviders(iterable $providers)
144141
{
145142
$expressionLanguage = new ExpressionLanguage(null, $providers);
@@ -161,18 +158,14 @@ public static function providerTestCases(): iterable
161158
})()];
162159
}
163160

164-
/**
165-
* @dataProvider shortCircuitProviderEvaluate
166-
*/
161+
#[DataProvider('shortCircuitProviderEvaluate')]
167162
public function testShortCircuitOperatorsEvaluate($expression, array $values, $expected)
168163
{
169164
$expressionLanguage = new ExpressionLanguage();
170165
$this->assertSame($expected, $expressionLanguage->evaluate($expression, $values));
171166
}
172167

173-
/**
174-
* @dataProvider shortCircuitProviderCompile
175-
*/
168+
#[DataProvider('shortCircuitProviderCompile')]
176169
public function testShortCircuitOperatorsCompile($expression, array $names, $expected)
177170
{
178171
$result = null;
@@ -304,9 +297,7 @@ public function testOperatorCollisions()
304297
$this->assertTrue($result);
305298
}
306299

307-
/**
308-
* @dataProvider getRegisterCallbacks
309-
*/
300+
#[DataProvider('getRegisterCallbacks')]
310301
public function testRegisterAfterParse($registerCallback)
311302
{
312303
$this->expectException(\LogicException::class);
@@ -315,9 +306,7 @@ public function testRegisterAfterParse($registerCallback)
315306
$registerCallback($el);
316307
}
317308

318-
/**
319-
* @dataProvider getRegisterCallbacks
320-
*/
309+
#[DataProvider('getRegisterCallbacks')]
321310
public function testRegisterAfterEval($registerCallback)
322311
{
323312
$this->expectException(\LogicException::class);
@@ -326,18 +315,14 @@ public function testRegisterAfterEval($registerCallback)
326315
$registerCallback($el);
327316
}
328317

329-
/**
330-
* @dataProvider provideNullSafe
331-
*/
318+
#[DataProvider('provideNullSafe')]
332319
public function testNullSafeEvaluate($expression, $foo)
333320
{
334321
$expressionLanguage = new ExpressionLanguage();
335322
$this->assertNull($expressionLanguage->evaluate($expression, ['foo' => $foo]));
336323
}
337324

338-
/**
339-
* @dataProvider provideNullSafe
340-
*/
325+
#[DataProvider('provideNullSafe')]
341326
public function testNullSafeCompile($expression, $foo)
342327
{
343328
$expressionLanguage = new ExpressionLanguage();
@@ -374,9 +359,7 @@ public function bar()
374359
yield ['foo?.bar()["baz"]["qux"].quux()', null];
375360
}
376361

377-
/**
378-
* @dataProvider provideInvalidNullSafe
379-
*/
362+
#[DataProvider('provideInvalidNullSafe')]
380363
public function testNullSafeEvaluateFails($expression, $foo, $message)
381364
{
382365
$expressionLanguage = new ExpressionLanguage();
@@ -386,9 +369,7 @@ public function testNullSafeEvaluateFails($expression, $foo, $message)
386369
$expressionLanguage->evaluate($expression, ['foo' => $foo]);
387370
}
388371

389-
/**
390-
* @dataProvider provideInvalidNullSafe
391-
*/
372+
#[DataProvider('provideInvalidNullSafe')]
392373
public function testNullSafeCompileFails($expression, $foo)
393374
{
394375
$expressionLanguage = new ExpressionLanguage();
@@ -417,18 +398,14 @@ public static function provideInvalidNullSafe()
417398
yield ['foo?.bar["baz"].qux.quux', (object) ['bar' => ['baz' => null]], 'Unable to get property "qux" of non-object "foo?.bar["baz"]".'];
418399
}
419400

420-
/**
421-
* @dataProvider provideNullCoalescing
422-
*/
401+
#[DataProvider('provideNullCoalescing')]
423402
public function testNullCoalescingEvaluate($expression, $foo)
424403
{
425404
$expressionLanguage = new ExpressionLanguage();
426405
$this->assertSame($expressionLanguage->evaluate($expression, ['foo' => $foo]), 'default');
427406
}
428407

429-
/**
430-
* @dataProvider provideNullCoalescing
431-
*/
408+
#[DataProvider('provideNullCoalescing')]
432409
public function testNullCoalescingCompile($expression, $foo)
433410
{
434411
$expressionLanguage = new ExpressionLanguage();
@@ -459,9 +436,7 @@ public function bar()
459436
yield ['foo[123][456][789] ?? "default"', [123 => []]];
460437
}
461438

462-
/**
463-
* @dataProvider getRegisterCallbacks
464-
*/
439+
#[DataProvider('getRegisterCallbacks')]
465440
public function testRegisterAfterCompile($registerCallback)
466441
{
467442
$this->expectException(\LogicException::class);
@@ -478,9 +453,7 @@ public static function validCommentProvider()
478453
yield ["/* multi\nline */ 'foo'"];
479454
}
480455

481-
/**
482-
* @dataProvider validCommentProvider
483-
*/
456+
#[DataProvider('validCommentProvider')]
484457
public function testLintAllowsComments($expression)
485458
{
486459
$el = new ExpressionLanguage();
@@ -496,9 +469,7 @@ public static function invalidCommentProvider()
496469
yield ['1 /* double closing */ */'];
497470
}
498471

499-
/**
500-
* @dataProvider invalidCommentProvider
501-
*/
472+
#[DataProvider('invalidCommentProvider')]
502473
public function testLintThrowsOnInvalidComments($expression)
503474
{
504475
$el = new ExpressionLanguage();

Tests/LexerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\ExpressionLanguage\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\ExpressionLanguage\Lexer;
1617
use Symfony\Component\ExpressionLanguage\SyntaxError;
@@ -26,9 +27,7 @@ protected function setUp(): void
2627
$this->lexer = new Lexer();
2728
}
2829

29-
/**
30-
* @dataProvider getTokenizeData
31-
*/
30+
#[DataProvider('getTokenizeData')]
3231
public function testTokenize($tokens, $expression)
3332
{
3433
$tokens[] = new Token('end of expression', null, \strlen($expression) + 1);

Tests/Node/AbstractNodeTestCase.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,21 @@
1111

1212
namespace Symfony\Component\ExpressionLanguage\Tests\Node;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\ExpressionLanguage\Compiler;
1617

1718
abstract class AbstractNodeTestCase extends TestCase
1819
{
19-
/**
20-
* @dataProvider getEvaluateData
21-
*/
20+
#[DataProvider('getEvaluateData')]
2221
public function testEvaluate($expected, $node, $variables = [], $functions = [])
2322
{
2423
$this->assertSame($expected, $node->evaluate($functions, $variables));
2524
}
2625

2726
abstract public static function getEvaluateData();
2827

29-
/**
30-
* @dataProvider getCompileData
31-
*/
28+
#[DataProvider('getCompileData')]
3229
public function testCompile($expected, $node, $functions = [])
3330
{
3431
$compiler = new Compiler($functions);
@@ -38,9 +35,7 @@ public function testCompile($expected, $node, $functions = [])
3835

3936
abstract public static function getCompileData();
4037

41-
/**
42-
* @dataProvider getDumpData
43-
*/
38+
#[DataProvider('getDumpData')]
4439
public function testDump($expected, $node)
4540
{
4641
$this->assertSame($expected, $node->dump());

Tests/Node/BinaryNodeTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\ExpressionLanguage\Tests\Node;
1313

14+
use PHPUnit\Framework\Attributes\TestWith;
1415
use Symfony\Component\ExpressionLanguage\Compiler;
1516
use Symfony\Component\ExpressionLanguage\Node\ArrayNode;
1617
use Symfony\Component\ExpressionLanguage\Node\BinaryNode;
@@ -265,10 +266,8 @@ public function testModuloByZero()
265266
$node->evaluate([], []);
266267
}
267268

268-
/**
269-
* @testWith [1]
270-
* ["true"]
271-
*/
269+
#[TestWith([1])]
270+
#[TestWith(['true'])]
272271
public function testInOperatorStrictness(mixed $value)
273272
{
274273
$array = new ArrayNode();

Tests/ParserTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\ExpressionLanguage\Tests;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\ExpressionLanguage\Lexer;
1617
use Symfony\Component\ExpressionLanguage\Node;
@@ -59,9 +60,7 @@ public function testParseUnknownFunction()
5960
$parser->parse($tokenized);
6061
}
6162

62-
/**
63-
* @dataProvider getParseData
64-
*/
63+
#[DataProvider('getParseData')]
6564
public function testParse($node, $expression, $names = [])
6665
{
6766
$lexer = new Lexer();
@@ -269,9 +268,7 @@ private static function createGetAttrNode($node, $item, $type)
269268
return new Node\GetAttrNode($node, new Node\ConstantNode($item, Node\GetAttrNode::ARRAY_CALL !== $type), new Node\ArgumentsNode(), $type);
270269
}
271270

272-
/**
273-
* @dataProvider getInvalidPostfixData
274-
*/
271+
#[DataProvider('getInvalidPostfixData')]
275272
public function testParseWithInvalidPostfixData($expr, $names = [])
276273
{
277274
$this->expectException(SyntaxError::class);
@@ -312,9 +309,7 @@ public function testNameProposal()
312309
$parser->parse($lexer->tokenize('foo > bar'), ['foo', 'baz']);
313310
}
314311

315-
/**
316-
* @dataProvider getLintData
317-
*/
312+
#[DataProvider('getLintData')]
318313
public function testLint($expression, $names, int $checks = 0, ?string $exception = null)
319314
{
320315
if ($exception) {

0 commit comments

Comments
 (0)