php_unit_method_casing.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ===============================
  2. Rule ``php_unit_method_casing``
  3. ===============================
  4. Enforce camel (or snake) case for PHPUnit test methods, following configuration.
  5. Configuration
  6. -------------
  7. ``case``
  8. ~~~~~~~~
  9. Apply camel or snake case to test methods.
  10. Allowed values: ``'camel_case'`` and ``'snake_case'``
  11. Default value: ``'camel_case'``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. class MyTest extends \PhpUnit\FrameWork\TestCase
  22. {
  23. - public function test_my_code() {}
  24. + public function testMyCode() {}
  25. }
  26. Example #2
  27. ~~~~~~~~~~
  28. With configuration: ``['case' => 'snake_case']``.
  29. .. code-block:: diff
  30. --- Original
  31. +++ New
  32. <?php
  33. class MyTest extends \PhpUnit\FrameWork\TestCase
  34. {
  35. - public function testMyCode() {}
  36. + public function test_my_code() {}
  37. }
  38. Example #3
  39. ~~~~~~~~~~
  40. *Default* configuration.
  41. .. code-block:: diff
  42. --- Original
  43. +++ New
  44. <?php
  45. use \PHPUnit\Framework\Attributes\Test;
  46. class MyTest extends \PhpUnit\FrameWork\TestCase
  47. {
  48. #[PHPUnit\Framework\Attributes\Test]
  49. - public function test_my_code() {}
  50. + public function testMyCode() {}
  51. }
  52. Example #4
  53. ~~~~~~~~~~
  54. With configuration: ``['case' => 'snake_case']``.
  55. .. code-block:: diff
  56. --- Original
  57. +++ New
  58. <?php
  59. use \PHPUnit\Framework\Attributes\Test;
  60. class MyTest extends \PhpUnit\FrameWork\TestCase
  61. {
  62. #[PHPUnit\Framework\Attributes\Test]
  63. - public function testMyCode() {}
  64. + public function test_my_code() {}
  65. }
  66. Rule sets
  67. ---------
  68. The rule is part of the following rule sets:
  69. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  70. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  71. References
  72. ----------
  73. - Fixer class: `PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitMethodCasingFixer <./../../../src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php>`_
  74. - Test class: `PhpCsFixer\\Tests\\Fixer\\PhpUnit\\PhpUnitMethodCasingFixerTest <./../../../tests/Fixer/PhpUnit/PhpUnitMethodCasingFixerTest.php>`_
  75. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.