1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
|
From: =?utf-8?q?David_Pr=C3=A9vot?= <taffit@debian.org>
Date: Mon, 17 Feb 2025 19:58:32 +0100
Subject: Modernize PHPUnit syntax
---
test/PhpParser/Builder/ClassConstTest.php | 5 ++--
test/PhpParser/Builder/EnumCaseTest.php | 5 ++--
test/PhpParser/Builder/ParamTest.php | 13 ++++-----
test/PhpParser/Builder/PropertyTest.php | 5 ++--
test/PhpParser/BuilderFactoryTest.php | 5 ++--
test/PhpParser/CodeParsingTest.php | 5 ++--
test/PhpParser/CommentTest.php | 6 ++--
test/PhpParser/ConstExprEvaluatorTest.php | 7 ++---
test/PhpParser/ErrorTest.php | 9 +++---
test/PhpParser/Internal/DifferTest.php | 6 ++--
test/PhpParser/JsonDecoderTest.php | 4 ++-
test/PhpParser/Lexer/EmulativeTest.php | 37 +++++++------------------
test/PhpParser/LexerTest.php | 10 +++----
test/PhpParser/NameContextTest.php | 5 ++--
test/PhpParser/Node/Expr/CallableLikeTest.php | 5 ++--
test/PhpParser/Node/IdentifierTest.php | 4 ++-
test/PhpParser/Node/NameTest.php | 4 ++-
test/PhpParser/Node/ParamTest.php | 5 ++--
test/PhpParser/Node/PropertyHookTest.php | 5 ++--
test/PhpParser/Node/Scalar/MagicConstTest.php | 6 ++--
test/PhpParser/Node/Scalar/StringTest.php | 9 ++----
test/PhpParser/Node/Stmt/ClassConstTest.php | 5 ++--
test/PhpParser/Node/Stmt/ClassMethodTest.php | 11 +++-----
test/PhpParser/Node/Stmt/PropertyTest.php | 5 ++--
test/PhpParser/NodeAbstractTest.php | 18 ++++--------
test/PhpParser/NodeDumperTest.php | 6 ++--
test/PhpParser/NodeTraverserTest.php | 5 ++--
test/PhpParser/NodeVisitor/NameResolverTest.php | 5 ++--
test/PhpParser/ParserTestAbstract.php | 5 ++--
test/PhpParser/PrettyPrinterTest.php | 23 +++++----------
test/PhpParser/TokenTest.php | 4 ++-
31 files changed, 100 insertions(+), 147 deletions(-)
diff --git a/test/PhpParser/Builder/ClassConstTest.php b/test/PhpParser/Builder/ClassConstTest.php
index ac6590b..232d046 100644
--- a/test/PhpParser/Builder/ClassConstTest.php
+++ b/test/PhpParser/Builder/ClassConstTest.php
@@ -14,6 +14,7 @@ use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Stmt;
+use PHPUnit\Framework\Attributes\DataProvider;
class ClassConstTest extends \PHPUnit\Framework\TestCase {
public function createClassConstBuilder($name, $value) {
@@ -154,9 +155,7 @@ class ClassConstTest extends \PHPUnit\Framework\TestCase {
);
}
- /**
- * @dataProvider provideTestDefaultValues
- */
+ #[DataProvider('provideTestDefaultValues')]
public function testValues($value, $expectedValueNode): void {
$node = $this->createClassConstBuilder('TEST', $value)
->getNode()
diff --git a/test/PhpParser/Builder/EnumCaseTest.php b/test/PhpParser/Builder/EnumCaseTest.php
index 04c032c..ad3a508 100644
--- a/test/PhpParser/Builder/EnumCaseTest.php
+++ b/test/PhpParser/Builder/EnumCaseTest.php
@@ -11,6 +11,7 @@ use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Stmt;
+use PHPUnit\Framework\Attributes\DataProvider;
class EnumCaseTest extends \PHPUnit\Framework\TestCase {
public function createEnumCaseBuilder($name) {
@@ -56,9 +57,7 @@ class EnumCaseTest extends \PHPUnit\Framework\TestCase {
);
}
- /**
- * @dataProvider provideTestDefaultValues
- */
+ #[DataProvider('provideTestDefaultValues')]
public function testValues($value, $expectedValueNode): void {
$node = $this->createEnumCaseBuilder('TEST')
->setValue($value)
diff --git a/test/PhpParser/Builder/ParamTest.php b/test/PhpParser/Builder/ParamTest.php
index 56eee0a..8f037cb 100644
--- a/test/PhpParser/Builder/ParamTest.php
+++ b/test/PhpParser/Builder/ParamTest.php
@@ -12,15 +12,14 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Int_;
+use PHPUnit\Framework\Attributes\DataProvider;
class ParamTest extends \PHPUnit\Framework\TestCase {
public function createParamBuilder($name) {
return new Param($name);
}
- /**
- * @dataProvider provideTestDefaultValues
- */
+ #[DataProvider('provideTestDefaultValues')]
public function testDefaultValues($value, $expectedValueNode): void {
$node = $this->createParamBuilder('test')
->setDefault($value)
@@ -84,11 +83,9 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
];
}
- /**
- * @dataProvider provideTestTypes
- * @dataProvider provideTestNullableTypes
- * @dataProvider provideTestUnionTypes
- */
+ #[DataProvider('provideTestTypes')]
+ #[DataProvider('provideTestNullableTypes')]
+ #[DataProvider('provideTestUnionTypes')]
public function testTypes($typeHint, $expectedType): void {
$node = $this->createParamBuilder('test')
->setType($typeHint)
diff --git a/test/PhpParser/Builder/PropertyTest.php b/test/PhpParser/Builder/PropertyTest.php
index 0505327..9067cd4 100644
--- a/test/PhpParser/Builder/PropertyTest.php
+++ b/test/PhpParser/Builder/PropertyTest.php
@@ -16,6 +16,7 @@ use PhpParser\Node\PropertyItem;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Stmt;
+use PHPUnit\Framework\Attributes\DataProvider;
class PropertyTest extends \PHPUnit\Framework\TestCase {
public function createPropertyBuilder($name) {
@@ -120,9 +121,7 @@ class PropertyTest extends \PHPUnit\Framework\TestCase {
), $node);
}
- /**
- * @dataProvider provideTestDefaultValues
- */
+ #[DataProvider('provideTestDefaultValues')]
public function testDefaultValues($value, $expectedValueNode): void {
$node = $this->createPropertyBuilder('test')
->setDefault($value)
diff --git a/test/PhpParser/BuilderFactoryTest.php b/test/PhpParser/BuilderFactoryTest.php
index 4f807c0..0f16b2e 100644
--- a/test/PhpParser/BuilderFactoryTest.php
+++ b/test/PhpParser/BuilderFactoryTest.php
@@ -10,11 +10,10 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\String_;
+use PHPUnit\Framework\Attributes\DataProvider;
class BuilderFactoryTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideTestFactory
- */
+ #[DataProvider('provideTestFactory')]
public function testFactory($methodName, $className): void {
$factory = new BuilderFactory();
$this->assertInstanceOf($className, $factory->$methodName('test'));
diff --git a/test/PhpParser/CodeParsingTest.php b/test/PhpParser/CodeParsingTest.php
index 0c479a5..d22530a 100644
--- a/test/PhpParser/CodeParsingTest.php
+++ b/test/PhpParser/CodeParsingTest.php
@@ -4,11 +4,10 @@ namespace PhpParser;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt;
+use PHPUnit\Framework\Attributes\DataProvider;
class CodeParsingTest extends CodeTestAbstract {
- /**
- * @dataProvider provideTestParse
- */
+ #[DataProvider('provideTestParse')]
public function testParse($name, $code, $expected, $modeLine): void {
$modes = $this->parseModeLine($modeLine);
$parser = $this->createParser($modes['version'] ?? null);
diff --git a/test/PhpParser/CommentTest.php b/test/PhpParser/CommentTest.php
index 1d0f0eb..b2d920b 100644
--- a/test/PhpParser/CommentTest.php
+++ b/test/PhpParser/CommentTest.php
@@ -2,6 +2,8 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class CommentTest extends \PHPUnit\Framework\TestCase {
public function testGetters(): void {
$comment = new Comment('/* Some comment */',
@@ -17,9 +19,7 @@ class CommentTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(2, $comment->getEndTokenPos());
}
- /**
- * @dataProvider provideTestReformatting
- */
+ #[DataProvider('provideTestReformatting')]
public function testReformatting($commentText, $reformattedText): void {
$comment = new Comment($commentText);
$this->assertSame($reformattedText, $comment->getReformattedText());
diff --git a/test/PhpParser/ConstExprEvaluatorTest.php b/test/PhpParser/ConstExprEvaluatorTest.php
index 513918e..589c31a 100644
--- a/test/PhpParser/ConstExprEvaluatorTest.php
+++ b/test/PhpParser/ConstExprEvaluatorTest.php
@@ -4,9 +4,10 @@ namespace PhpParser;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar;
+use PHPUnit\Framework\Attributes\DataProvider;
class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
- /** @dataProvider provideTestEvaluate */
+ #[DataProvider('provideTestEvaluate')]
public function testEvaluate($exprString, $expected): void {
$parser = (new ParserFactory())->createForNewestSupportedVersion();
$expr = $parser->parse('<?php ' . $exprString . ';')[0]->expr;
@@ -96,9 +97,7 @@ class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase {
$this->assertSame(50, $evaluator->evaluateDirectly($expr));
}
- /**
- * @dataProvider provideTestEvaluateSilently
- */
+ #[DataProvider('provideTestEvaluateSilently')]
public function testEvaluateSilently($expr, $exception, $msg): void {
$evaluator = new ConstExprEvaluator();
diff --git a/test/PhpParser/ErrorTest.php b/test/PhpParser/ErrorTest.php
index b86412e..3c1f089 100644
--- a/test/PhpParser/ErrorTest.php
+++ b/test/PhpParser/ErrorTest.php
@@ -2,6 +2,9 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\Depends;
+
class ErrorTest extends \PHPUnit\Framework\TestCase {
public function testConstruct() {
$attributes = [
@@ -19,9 +22,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
return $error;
}
- /**
- * @depends testConstruct
- */
+ #[Depends('testConstruct')]
public function testSetMessageAndLine(Error $error): void {
$error->setRawMessage('Some other error');
$this->assertSame('Some other error', $error->getRawMessage());
@@ -39,7 +40,7 @@ class ErrorTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('Some error on unknown line', $error->getMessage());
}
- /** @dataProvider provideTestColumnInfo */
+ #[DataProvider('provideTestColumnInfo')]
public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn): void {
$error = new Error('Some error', [
'startFilePos' => $startPos,
diff --git a/test/PhpParser/Internal/DifferTest.php b/test/PhpParser/Internal/DifferTest.php
index a50ca66..3d53b7d 100644
--- a/test/PhpParser/Internal/DifferTest.php
+++ b/test/PhpParser/Internal/DifferTest.php
@@ -2,6 +2,8 @@
namespace PhpParser\Internal;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class DifferTest extends \PHPUnit\Framework\TestCase {
private function formatDiffString(array $diff) {
$diffStr = '';
@@ -27,7 +29,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
return $diffStr;
}
- /** @dataProvider provideTestDiff */
+ #[DataProvider('provideTestDiff')]
public function testDiff($oldStr, $newStr, $expectedDiffStr): void {
$differ = new Differ(function ($a, $b) {
return $a === $b;
@@ -48,7 +50,7 @@ class DifferTest extends \PHPUnit\Framework\TestCase {
];
}
- /** @dataProvider provideTestDiffWithReplacements */
+ #[DataProvider('provideTestDiffWithReplacements')]
public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr): void {
$differ = new Differ(function ($a, $b) {
return $a === $b;
diff --git a/test/PhpParser/JsonDecoderTest.php b/test/PhpParser/JsonDecoderTest.php
index 9f1e837..b6cf452 100644
--- a/test/PhpParser/JsonDecoderTest.php
+++ b/test/PhpParser/JsonDecoderTest.php
@@ -2,6 +2,8 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class JsonDecoderTest extends \PHPUnit\Framework\TestCase {
public function testRoundTrip(): void {
$code = <<<'PHP'
@@ -22,7 +24,7 @@ PHP;
$this->assertEquals($stmts, $decodedStmts);
}
- /** @dataProvider provideTestDecodingError */
+ #[DataProvider('provideTestDecodingError')]
public function testDecodingError($json, $expectedMessage): void {
$jsonDecoder = new JsonDecoder();
$this->expectException(\RuntimeException::class);
diff --git a/test/PhpParser/Lexer/EmulativeTest.php b/test/PhpParser/Lexer/EmulativeTest.php
index 2613289..ffe4370 100644
--- a/test/PhpParser/Lexer/EmulativeTest.php
+++ b/test/PhpParser/Lexer/EmulativeTest.php
@@ -8,6 +8,7 @@ use PhpParser\LexerTest;
use PhpParser\Parser\Php7;
use PhpParser\PhpVersion;
use PhpParser\Token;
+use PHPUnit\Framework\Attributes\DataProvider;
require __DIR__ . '/../../../lib/PhpParser/compatibility_tokens.php';
@@ -16,9 +17,7 @@ class EmulativeTest extends LexerTest {
return new Emulative();
}
- /**
- * @dataProvider provideTestReplaceKeywords
- */
+ #[DataProvider('provideTestReplaceKeywords')]
public function testReplaceKeywords(string $keyword, int $expectedToken): void {
$lexer = $this->getLexer();
$code = '<?php ' . $keyword;
@@ -29,9 +28,7 @@ class EmulativeTest extends LexerTest {
], $lexer->tokenize($code));
}
- /**
- * @dataProvider provideTestReplaceKeywords
- */
+ #[DataProvider('provideTestReplaceKeywords')]
public function testReplaceKeywordsUppercase(string $keyword, int $expectedToken): void {
$lexer = $this->getLexer();
$code = '<?php ' . strtoupper($keyword);
@@ -43,9 +40,7 @@ class EmulativeTest extends LexerTest {
], $lexer->tokenize($code));
}
- /**
- * @dataProvider provideTestReplaceKeywords
- */
+ #[DataProvider('provideTestReplaceKeywords')]
public function testNoReplaceKeywordsAfterObjectOperator(string $keyword): void {
$lexer = $this->getLexer();
$code = '<?php ->' . $keyword;
@@ -58,9 +53,7 @@ class EmulativeTest extends LexerTest {
], $lexer->tokenize($code));
}
- /**
- * @dataProvider provideTestReplaceKeywords
- */
+ #[DataProvider('provideTestReplaceKeywords')]
public function testNoReplaceKeywordsAfterObjectOperatorWithSpaces(string $keyword): void {
$lexer = $this->getLexer();
$code = '<?php -> ' . $keyword;
@@ -74,9 +67,7 @@ class EmulativeTest extends LexerTest {
], $lexer->tokenize($code));
}
- /**
- * @dataProvider provideTestReplaceKeywords
- */
+ #[DataProvider('provideTestReplaceKeywords')]
public function testNoReplaceKeywordsAfterNullsafeObjectOperator(string $keyword): void {
$lexer = $this->getLexer();
$code = '<?php ?->' . $keyword;
@@ -129,17 +120,13 @@ class EmulativeTest extends LexerTest {
$this->assertSame($expectedTokens, $reducedTokens);
}
- /**
- * @dataProvider provideTestLexNewFeatures
- */
+ #[DataProvider('provideTestLexNewFeatures')]
public function testLexNewFeatures(string $code, array $expectedTokens): void {
$lexer = $this->getLexer();
$this->assertSameTokens($expectedTokens, $lexer->tokenize('<?php ' . $code));
}
- /**
- * @dataProvider provideTestLexNewFeatures
- */
+ #[DataProvider('provideTestLexNewFeatures')]
public function testLeaveStuffAloneInStrings(string $code): void {
$stringifiedToken = '"' . addcslashes($code, '"\\') . '"';
@@ -153,9 +140,7 @@ class EmulativeTest extends LexerTest {
], $lexer->tokenize($fullCode));
}
- /**
- * @dataProvider provideTestLexNewFeatures
- */
+ #[DataProvider('provideTestLexNewFeatures')]
public function testErrorAfterEmulation($code): void {
$errorHandler = new ErrorHandler\Collecting();
$lexer = $this->getLexer();
@@ -448,9 +433,7 @@ class EmulativeTest extends LexerTest {
];
}
- /**
- * @dataProvider provideTestTargetVersion
- */
+ #[DataProvider('provideTestTargetVersion')]
public function testTargetVersion(string $phpVersion, string $code, array $expectedTokens): void {
$lexer = new Emulative(PhpVersion::fromString($phpVersion));
$this->assertSameTokens($expectedTokens, $lexer->tokenize('<?php ' . $code));
diff --git a/test/PhpParser/LexerTest.php b/test/PhpParser/LexerTest.php
index c70d83e..0c770cd 100644
--- a/test/PhpParser/LexerTest.php
+++ b/test/PhpParser/LexerTest.php
@@ -2,6 +2,8 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+
require __DIR__ . '/../../lib/PhpParser/compatibility_tokens.php';
class LexerTest extends \PHPUnit\Framework\TestCase {
@@ -10,9 +12,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
return new Lexer();
}
- /**
- * @dataProvider provideTestError
- */
+ #[DataProvider('provideTestError')]
public function testError($code, $messages): void {
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM does not throw warnings from token_get_all()');
@@ -52,9 +52,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase {
$lexer->tokenize("<?php readonly /*");
}
- /**
- * @dataProvider provideTestLex
- */
+ #[DataProvider('provideTestLex')]
public function testLex($code, $expectedTokens): void {
$lexer = $this->getLexer();
$tokens = $lexer->tokenize($code);
diff --git a/test/PhpParser/NameContextTest.php b/test/PhpParser/NameContextTest.php
index 1c8295e..7b99a0e 100644
--- a/test/PhpParser/NameContextTest.php
+++ b/test/PhpParser/NameContextTest.php
@@ -4,11 +4,10 @@ namespace PhpParser;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Use_;
+use PHPUnit\Framework\Attributes\DataProvider;
class NameContextTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideTestGetPossibleNames
- */
+ #[DataProvider('provideTestGetPossibleNames')]
public function testGetPossibleNames($type, $name, $expectedPossibleNames): void {
$nameContext = new NameContext(new ErrorHandler\Throwing());
$nameContext->startNamespace(new Name('NS'));
diff --git a/test/PhpParser/Node/Expr/CallableLikeTest.php b/test/PhpParser/Node/Expr/CallableLikeTest.php
index 618c972..06b981e 100644
--- a/test/PhpParser/Node/Expr/CallableLikeTest.php
+++ b/test/PhpParser/Node/Expr/CallableLikeTest.php
@@ -7,11 +7,10 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\VariadicPlaceholder;
+use PHPUnit\Framework\Attributes\DataProvider;
class CallableLikeTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideTestIsFirstClassCallable
- */
+ #[DataProvider('provideTestIsFirstClassCallable')]
public function testIsFirstClassCallable(CallLike $node, bool $isFirstClassCallable): void {
$this->assertSame($isFirstClassCallable, $node->isFirstClassCallable());
if (!$isFirstClassCallable) {
diff --git a/test/PhpParser/Node/IdentifierTest.php b/test/PhpParser/Node/IdentifierTest.php
index fa3e066..8d12dba 100644
--- a/test/PhpParser/Node/IdentifierTest.php
+++ b/test/PhpParser/Node/IdentifierTest.php
@@ -2,6 +2,8 @@
namespace PhpParser\Node;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class IdentifierTest extends \PHPUnit\Framework\TestCase {
public function testConstructorThrows(): void {
self::expectException(\InvalidArgumentException::class);
@@ -16,7 +18,7 @@ class IdentifierTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('foo', $identifier->toLowerString());
}
- /** @dataProvider provideTestIsSpecialClassName */
+ #[DataProvider('provideTestIsSpecialClassName')]
public function testIsSpecialClassName($identifier, $expected): void {
$identifier = new Identifier($identifier);
$this->assertSame($expected, $identifier->isSpecialClassName());
diff --git a/test/PhpParser/Node/NameTest.php b/test/PhpParser/Node/NameTest.php
index eb25d04..0c3f4d9 100644
--- a/test/PhpParser/Node/NameTest.php
+++ b/test/PhpParser/Node/NameTest.php
@@ -2,6 +2,8 @@
namespace PhpParser\Node;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class NameTest extends \PHPUnit\Framework\TestCase {
public function testConstruct(): void {
$name = new Name(['foo', 'bar']);
@@ -146,7 +148,7 @@ class NameTest extends \PHPUnit\Framework\TestCase {
new Name([]);
}
- /** @dataProvider provideTestIsSpecialClassName */
+ #[DataProvider('provideTestIsSpecialClassName')]
public function testIsSpecialClassName($name, $expected): void {
$name = new Name($name);
$this->assertSame($expected, $name->isSpecialClassName());
diff --git a/test/PhpParser/Node/ParamTest.php b/test/PhpParser/Node/ParamTest.php
index e4b670c..22200ca 100644
--- a/test/PhpParser/Node/ParamTest.php
+++ b/test/PhpParser/Node/ParamTest.php
@@ -4,6 +4,7 @@ namespace PhpParser\Node;
use PhpParser\Modifiers;
use PhpParser\Node\Expr\Variable;
+use PHPUnit\Framework\Attributes\DataProvider;
class ParamTest extends \PHPUnit\Framework\TestCase {
public function testNoModifiers(): void {
@@ -19,9 +20,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($node->isPrivateSet());
}
- /**
- * @dataProvider provideModifiers
- */
+ #[DataProvider('provideModifiers')]
public function testModifiers(string $modifier): void {
$node = new Param(new Variable('foo'));
$node->flags = constant(Modifiers::class . '::' . strtoupper($modifier));
diff --git a/test/PhpParser/Node/PropertyHookTest.php b/test/PhpParser/Node/PropertyHookTest.php
index 8e5cf99..65e126a 100644
--- a/test/PhpParser/Node/PropertyHookTest.php
+++ b/test/PhpParser/Node/PropertyHookTest.php
@@ -11,11 +11,10 @@ use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;
+use PHPUnit\Framework\Attributes\DataProvider;
class PropertyHookTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideModifiers
- */
+ #[DataProvider('provideModifiers')]
public function testModifiers($modifier): void {
$node = new PropertyHook(
'get',
diff --git a/test/PhpParser/Node/Scalar/MagicConstTest.php b/test/PhpParser/Node/Scalar/MagicConstTest.php
index 825b1b1..2c97ced 100644
--- a/test/PhpParser/Node/Scalar/MagicConstTest.php
+++ b/test/PhpParser/Node/Scalar/MagicConstTest.php
@@ -2,10 +2,10 @@
namespace PhpParser\Node\Scalar;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class MagicConstTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideTestGetName
- */
+ #[DataProvider('provideTestGetName')]
public function testGetName(MagicConst $magicConst, $name): void {
$this->assertSame($name, $magicConst->getName());
}
diff --git a/test/PhpParser/Node/Scalar/StringTest.php b/test/PhpParser/Node/Scalar/StringTest.php
index cb0968c..c5a2473 100644
--- a/test/PhpParser/Node/Scalar/StringTest.php
+++ b/test/PhpParser/Node/Scalar/StringTest.php
@@ -4,6 +4,7 @@ namespace PhpParser\Node\Scalar;
use PhpParser\Node\Stmt\Echo_;
use PhpParser\ParserFactory;
+use PHPUnit\Framework\Attributes\DataProvider;
class StringTest extends \PHPUnit\Framework\TestCase {
public function testRawValue(): void {
@@ -22,9 +23,7 @@ class StringTest extends \PHPUnit\Framework\TestCase {
$this->assertSame('"sequence \\x41"', $string->getAttribute('rawValue'));
}
- /**
- * @dataProvider provideTestParseEscapeSequences
- */
+ #[DataProvider('provideTestParseEscapeSequences')]
public function testParseEscapeSequences($expected, $string, $quote): void {
$this->assertSame(
$expected,
@@ -32,9 +31,7 @@ class StringTest extends \PHPUnit\Framework\TestCase {
);
}
- /**
- * @dataProvider provideTestParse
- */
+ #[DataProvider('provideTestParse')]
public function testCreate($expected, $string): void {
$this->assertSame(
$expected,
diff --git a/test/PhpParser/Node/Stmt/ClassConstTest.php b/test/PhpParser/Node/Stmt/ClassConstTest.php
index 7206ebf..aaa4197 100644
--- a/test/PhpParser/Node/Stmt/ClassConstTest.php
+++ b/test/PhpParser/Node/Stmt/ClassConstTest.php
@@ -3,11 +3,10 @@
namespace PhpParser\Node\Stmt;
use PhpParser\Modifiers;
+use PHPUnit\Framework\Attributes\DataProvider;
class ClassConstTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideModifiers
- */
+ #[DataProvider('provideModifiers')]
public function testModifiers($modifier): void {
$node = new ClassConst(
[], // invalid
diff --git a/test/PhpParser/Node/Stmt/ClassMethodTest.php b/test/PhpParser/Node/Stmt/ClassMethodTest.php
index 17bb3ec..e4c08d8 100644
--- a/test/PhpParser/Node/Stmt/ClassMethodTest.php
+++ b/test/PhpParser/Node/Stmt/ClassMethodTest.php
@@ -6,11 +6,10 @@ use PhpParser\Modifiers;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Param;
+use PHPUnit\Framework\Attributes\DataProvider;
class ClassMethodTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideModifiers
- */
+ #[DataProvider('provideModifiers')]
public function testModifiers($modifier): void {
$node = new ClassMethod('foo', [
'type' => constant(Modifiers::class . '::' . strtoupper($modifier))
@@ -45,10 +44,9 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
/**
* Checks that implicit public modifier detection for method is working
*
- * @dataProvider implicitPublicModifiers
- *
* @param string $modifier Node type modifier
*/
+ #[DataProvider('implicitPublicModifiers')]
public function testImplicitPublic(string $modifier): void {
$node = new ClassMethod('foo', [
'type' => constant(Modifiers::class . '::' . strtoupper($modifier))
@@ -66,10 +64,9 @@ class ClassMethodTest extends \PHPUnit\Framework\TestCase {
}
/**
- * @dataProvider provideMagics
- *
* @param string $name Node name
*/
+ #[DataProvider('provideMagics')]
public function testMagic(string $name): void {
$node = new ClassMethod($name);
$this->assertTrue($node->isMagic(), 'Method should be magic');
diff --git a/test/PhpParser/Node/Stmt/PropertyTest.php b/test/PhpParser/Node/Stmt/PropertyTest.php
index 4eb252e..86456a9 100644
--- a/test/PhpParser/Node/Stmt/PropertyTest.php
+++ b/test/PhpParser/Node/Stmt/PropertyTest.php
@@ -3,11 +3,10 @@
namespace PhpParser\Node\Stmt;
use PhpParser\Modifiers;
+use PHPUnit\Framework\Attributes\DataProvider;
class PropertyTest extends \PHPUnit\Framework\TestCase {
- /**
- * @dataProvider provideModifiers
- */
+ #[DataProvider('provideModifiers')]
public function testModifiers($modifier): void {
$node = new Property(
constant(Modifiers::class . '::' . strtoupper($modifier)),
diff --git a/test/PhpParser/NodeAbstractTest.php b/test/PhpParser/NodeAbstractTest.php
index cdd193a..b6c3961 100644
--- a/test/PhpParser/NodeAbstractTest.php
+++ b/test/PhpParser/NodeAbstractTest.php
@@ -2,6 +2,8 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class DummyNode extends NodeAbstract {
public $subNode1;
public $subNode2;
@@ -47,9 +49,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
];
}
- /**
- * @dataProvider provideNodes
- */
+ #[DataProvider('provideNodes')]
public function testConstruct(array $attributes, Node $node) {
$this->assertSame('Dummy', $node->getType());
$this->assertSame(['subNode1', 'subNode2'], $node->getSubNodeNames());
@@ -72,9 +72,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
return $node;
}
- /**
- * @dataProvider provideNodes
- */
+ #[DataProvider('provideNodes')]
public function testGetDocComment(array $attributes, Node $node): void {
$this->assertSame('/** doc comment */', $node->getDocComment()->getText());
$comments = $node->getComments();
@@ -116,9 +114,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
$this->assertSame([$c1, $newDocComment, $c2], $node->getAttribute('comments'));
}
- /**
- * @dataProvider provideNodes
- */
+ #[DataProvider('provideNodes')]
public function testChange(array $attributes, DummyNode $node): void {
// direct modification
$node->subNode1 = 'newValue';
@@ -134,9 +130,7 @@ class NodeAbstractTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse(isset($node->subNode1));
}
- /**
- * @dataProvider provideNodes
- */
+ #[DataProvider('provideNodes')]
public function testIteration(array $attributes, Node $node): void {
// Iteration is simple object iteration over properties,
// not over subnodes
diff --git a/test/PhpParser/NodeDumperTest.php b/test/PhpParser/NodeDumperTest.php
index f0e65ca..b3dde2d 100644
--- a/test/PhpParser/NodeDumperTest.php
+++ b/test/PhpParser/NodeDumperTest.php
@@ -2,14 +2,14 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class NodeDumperTest extends \PHPUnit\Framework\TestCase {
private function canonicalize($string) {
return str_replace("\r\n", "\n", $string);
}
- /**
- * @dataProvider provideTestDump
- */
+ #[DataProvider('provideTestDump')]
public function testDump($node, $dump): void {
$dumper = new NodeDumper();
diff --git a/test/PhpParser/NodeTraverserTest.php b/test/PhpParser/NodeTraverserTest.php
index 09ea814..d63f242 100644
--- a/test/PhpParser/NodeTraverserTest.php
+++ b/test/PhpParser/NodeTraverserTest.php
@@ -7,6 +7,7 @@ use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
+use PHPUnit\Framework\Attributes\DataProvider;
class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
public function testNonModifying(): void {
@@ -412,9 +413,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
$this->assertSame($stmts, $traverser->traverse($stmts));
}
- /**
- * @dataProvider provideTestInvalidReturn
- */
+ #[DataProvider('provideTestInvalidReturn')]
public function testInvalidReturn($stmts, $visitor, $message): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage($message);
diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php
index a50a595..2d2a682 100644
--- a/test/PhpParser/NodeVisitor/NameResolverTest.php
+++ b/test/PhpParser/NodeVisitor/NameResolverTest.php
@@ -7,6 +7,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
+use PHPUnit\Framework\Attributes\DataProvider;
class NameResolverTest extends \PHPUnit\Framework\TestCase {
private function canonicalize($string) {
@@ -433,9 +434,7 @@ EOC;
$this->assertFalse($stmts[1]->stmts[1]->name->hasAttribute('namespacedName'));
}
- /**
- * @dataProvider provideTestError
- */
+ #[DataProvider('provideTestError')]
public function testError(Node $stmt, $errorMsg): void {
$this->expectException(\PhpParser\Error::class);
$this->expectExceptionMessage($errorMsg);
diff --git a/test/PhpParser/ParserTestAbstract.php b/test/PhpParser/ParserTestAbstract.php
index 9f083b2..df6f198 100644
--- a/test/PhpParser/ParserTestAbstract.php
+++ b/test/PhpParser/ParserTestAbstract.php
@@ -6,6 +6,7 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
+use PHPUnit\Framework\Attributes\DataProvider;
abstract class ParserTestAbstract extends \PHPUnit\Framework\TestCase {
/** @returns Parser */
@@ -115,9 +116,7 @@ EOC;
$parser->parse('dummy');
}
- /**
- * @dataProvider provideTestExtraAttributes
- */
+ #[DataProvider('provideTestExtraAttributes')]
public function testExtraAttributes($code, $expectedAttributes): void {
$parser = $this->getParser(new Lexer\Emulative());
$stmts = $parser->parse("<?php $code;");
diff --git a/test/PhpParser/PrettyPrinterTest.php b/test/PhpParser/PrettyPrinterTest.php
index 8e0e472..ce7d3f2 100644
--- a/test/PhpParser/PrettyPrinterTest.php
+++ b/test/PhpParser/PrettyPrinterTest.php
@@ -11,6 +11,7 @@ use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\PrettyPrinter\Standard;
+use PHPUnit\Framework\Attributes\DataProvider;
class PrettyPrinterTest extends CodeTestAbstract {
/** @return array{0: Parser, 1: PrettyPrinter} */
@@ -34,16 +35,12 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->assertSame($expected, $output, $name);
}
- /**
- * @dataProvider provideTestPrettyPrint
- */
+ #[DataProvider('provideTestPrettyPrint')]
public function testPrettyPrint($name, $code, $expected, $mode): void {
$this->doTestPrettyPrintMethod('prettyPrint', $name, $code, $expected, $mode);
}
- /**
- * @dataProvider provideTestPrettyPrintFile
- */
+ #[DataProvider('provideTestPrettyPrintFile')]
public function testPrettyPrintFile($name, $code, $expected, $mode): void {
$this->doTestPrettyPrintMethod('prettyPrintFile', $name, $code, $expected, $mode);
}
@@ -87,9 +84,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$this->assertSame($expected, $prettyPrinter->prettyPrintExpr($expr));
}
- /**
- * @dataProvider provideTestKindAttributes
- */
+ #[DataProvider('provideTestKindAttributes')]
public function testKindAttributes($node, $expected): void {
$prttyPrinter = new PrettyPrinter\Standard();
$result = $prttyPrinter->prettyPrintExpr($node);
@@ -145,7 +140,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
];
}
- /** @dataProvider provideTestUnnaturalLiterals */
+ #[DataProvider('provideTestUnnaturalLiterals')]
public function testUnnaturalLiterals($node, $expected): void {
$prttyPrinter = new PrettyPrinter\Standard();
$result = $prttyPrinter->prettyPrintExpr($node);
@@ -185,9 +180,7 @@ class PrettyPrinterTest extends CodeTestAbstract {
$prettyPrinter->prettyPrint($stmts);
}
- /**
- * @dataProvider provideTestFormatPreservingPrint
- */
+ #[DataProvider('provideTestFormatPreservingPrint')]
public function testFormatPreservingPrint($name, $code, $modification, $expected, $modeLine): void {
[$parser, $printer] = $this->createParserAndPrinter($this->parseModeLine($modeLine));
$traverser = new NodeTraverser(new NodeVisitor\CloningVisitor());
@@ -218,9 +211,7 @@ CODE
return self::getTests(__DIR__ . '/../code/formatPreservation', 'test', 3);
}
- /**
- * @dataProvider provideTestRoundTripPrint
- */
+ #[DataProvider('provideTestRoundTripPrint')]
public function testRoundTripPrint($name, $code, $expected, $modeLine): void {
/**
* This test makes sure that the format-preserving pretty printer round-trips for all
diff --git a/test/PhpParser/TokenTest.php b/test/PhpParser/TokenTest.php
index c015d9f..2c36dbe 100644
--- a/test/PhpParser/TokenTest.php
+++ b/test/PhpParser/TokenTest.php
@@ -2,6 +2,8 @@
namespace PhpParser;
+use PHPUnit\Framework\Attributes\DataProvider;
+
class TokenTest extends \PHPUnit\Framework\TestCase {
public function testGetTokenName(): void {
$token = new Token(\ord(','), ',');
@@ -22,7 +24,7 @@ class TokenTest extends \PHPUnit\Framework\TestCase {
$this->assertFalse($token->is(['!', ';']));
}
- /** @dataProvider provideTestIsIgnorable */
+ #[DataProvider('provideTestIsIgnorable')]
public function testIsIgnorable(int $id, string $text, bool $isIgnorable): void {
$token = new Token($id, $text);
$this->assertSame($isIgnorable, $token->isIgnorable());
|