php_unit_attributes.rst 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ============================
  2. Rule ``php_unit_attributes``
  3. ============================
  4. PHPUnit attributes must be used over their respective PHPDoc-based annotations.
  5. Examples
  6. --------
  7. Example #1
  8. ~~~~~~~~~~
  9. .. code-block:: diff
  10. --- Original
  11. +++ New
  12. <?php
  13. /**
  14. - * @covers \VendorName\Foo
  15. * @internal
  16. */
  17. +#[\PHPUnit\Framework\Attributes\CoversClass(\VendorName\Foo::class)]
  18. final class FooTest extends TestCase {
  19. /**
  20. * @param int $expected
  21. * @param int $actual
  22. - * @dataProvider giveMeSomeData
  23. - * @requires PHP 8.0
  24. */
  25. + #[\PHPUnit\Framework\Attributes\DataProvider('giveMeSomeData')]
  26. + #[\PHPUnit\Framework\Attributes\RequiresPhp('8.0')]
  27. public function testSomething($expected, $actual) {}
  28. }
  29. References
  30. ----------
  31. - Fixer class: `PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitAttributesFixer <./../../../src/Fixer/PhpUnit/PhpUnitAttributesFixer.php>`_
  32. - Test class: `PhpCsFixer\\Tests\\Fixer\\PhpUnit\\PhpUnitAttributesFixerTest <./../../../tests/Fixer/PhpUnit/PhpUnitAttributesFixerTest.php>`_
  33. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.