php_unit_strict.rst 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ========================
  2. Rule ``php_unit_strict``
  3. ========================
  4. PHPUnit methods like ``assertSame`` should be used instead of ``assertEquals``.
  5. .. warning:: Using this rule is risky.
  6. Risky when any of the functions are overridden or when testing object
  7. equality.
  8. Configuration
  9. -------------
  10. ``assertions``
  11. ~~~~~~~~~~~~~~
  12. List of assertion methods to fix.
  13. Allowed values: a subset of ``['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']``
  14. Default value: ``['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']``
  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->assertAttributeEquals(a(), b());
  29. - $this->assertAttributeNotEquals(a(), b());
  30. - $this->assertEquals(a(), b());
  31. - $this->assertNotEquals(a(), b());
  32. + $this->assertAttributeSame(a(), b());
  33. + $this->assertAttributeNotSame(a(), b());
  34. + $this->assertSame(a(), b());
  35. + $this->assertNotSame(a(), b());
  36. }
  37. }
  38. Example #2
  39. ~~~~~~~~~~
  40. With configuration: ``['assertions' => ['assertEquals']]``.
  41. .. code-block:: diff
  42. --- Original
  43. +++ New
  44. <?php
  45. final class MyTest extends \PHPUnit_Framework_TestCase
  46. {
  47. public function testSomeTest()
  48. {
  49. $this->assertAttributeEquals(a(), b());
  50. $this->assertAttributeNotEquals(a(), b());
  51. - $this->assertEquals(a(), b());
  52. + $this->assertSame(a(), b());
  53. $this->assertNotEquals(a(), b());
  54. }
  55. }
  56. Rule sets
  57. ---------
  58. The rule is part of the following rule set:
  59. @PhpCsFixer:risky
  60. Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``php_unit_strict`` rule with the default config.