php_unit_dedicate_assert.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. =================================
  2. Rule ``php_unit_dedicate_assert``
  3. =================================
  4. PHPUnit assertions like ``assertInternalType``, ``assertFileExists``, should be
  5. used over ``assertTrue``.
  6. .. warning:: Using this rule is risky.
  7. Fixer could be risky if one is overriding PHPUnit's native methods.
  8. Configuration
  9. -------------
  10. ``target``
  11. ~~~~~~~~~~
  12. Target version of PHPUnit.
  13. Allowed values: ``'3.0'``, ``'3.5'``, ``'5.0'``, ``'5.6'``, ``'newest'``
  14. Default value: ``'newest'``
  15. Examples
  16. --------
  17. Example #1
  18. ~~~~~~~~~~
  19. *Default* configuration.
  20. .. code-block:: diff
  21. --- Original
  22. +++ New
  23. <?php
  24. final class MyTest extends \PHPUnit_Framework_TestCase
  25. {
  26. public function testSomeTest()
  27. {
  28. - $this->assertTrue(is_float( $a), "my message");
  29. - $this->assertTrue(is_nan($a));
  30. + $this->assertInternalType('float', $a, "my message");
  31. + $this->assertNan($a);
  32. }
  33. }
  34. Example #2
  35. ~~~~~~~~~~
  36. With configuration: ``['target' => '5.6']``.
  37. .. code-block:: diff
  38. --- Original
  39. +++ New
  40. <?php
  41. final class MyTest extends \PHPUnit_Framework_TestCase
  42. {
  43. public function testSomeTest()
  44. {
  45. - $this->assertTrue(is_dir($a));
  46. - $this->assertTrue(is_writable($a));
  47. - $this->assertTrue(is_readable($a));
  48. + $this->assertDirectoryExists($a);
  49. + $this->assertIsWritable($a);
  50. + $this->assertIsReadable($a);
  51. }
  52. }
  53. Rule sets
  54. ---------
  55. The rule is part of the following rule sets:
  56. @PHPUnit30Migration:risky
  57. Using the `@PHPUnit30Migration:risky <./../../ruleSets/PHPUnit30MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  58. ``['target' => '3.0']``
  59. @PHPUnit32Migration:risky
  60. Using the `@PHPUnit32Migration:risky <./../../ruleSets/PHPUnit32MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  61. ``['target' => '3.0']``
  62. @PHPUnit35Migration:risky
  63. Using the `@PHPUnit35Migration:risky <./../../ruleSets/PHPUnit35MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  64. ``['target' => '3.5']``
  65. @PHPUnit43Migration:risky
  66. Using the `@PHPUnit43Migration:risky <./../../ruleSets/PHPUnit43MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  67. ``['target' => '3.5']``
  68. @PHPUnit48Migration:risky
  69. Using the `@PHPUnit48Migration:risky <./../../ruleSets/PHPUnit48MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  70. ``['target' => '3.5']``
  71. @PHPUnit50Migration:risky
  72. Using the `@PHPUnit50Migration:risky <./../../ruleSets/PHPUnit50MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  73. ``['target' => '5.0']``
  74. @PHPUnit52Migration:risky
  75. Using the `@PHPUnit52Migration:risky <./../../ruleSets/PHPUnit52MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  76. ``['target' => '5.0']``
  77. @PHPUnit54Migration:risky
  78. Using the `@PHPUnit54Migration:risky <./../../ruleSets/PHPUnit54MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  79. ``['target' => '5.0']``
  80. @PHPUnit55Migration:risky
  81. Using the `@PHPUnit55Migration:risky <./../../ruleSets/PHPUnit55MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  82. ``['target' => '5.0']``
  83. @PHPUnit56Migration:risky
  84. Using the `@PHPUnit56Migration:risky <./../../ruleSets/PHPUnit56MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  85. ``['target' => '5.6']``
  86. @PHPUnit57Migration:risky
  87. Using the `@PHPUnit57Migration:risky <./../../ruleSets/PHPUnit57MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  88. ``['target' => '5.6']``
  89. @PHPUnit60Migration:risky
  90. Using the `@PHPUnit60Migration:risky <./../../ruleSets/PHPUnit60MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  91. ``['target' => '5.6']``
  92. @PHPUnit75Migration:risky
  93. Using the `@PHPUnit75Migration:risky <./../../ruleSets/PHPUnit75MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  94. ``['target' => '5.6']``
  95. @PHPUnit84Migration:risky
  96. Using the `@PHPUnit84Migration:risky <./../../ruleSets/PHPUnit84MigrationRisky.rst>`_ rule set will enable the ``php_unit_dedicate_assert`` rule with the config below:
  97. ``['target' => '5.6']``