php_unit_strict.rst 1.9 KB

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