123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- =================================
- Rule ``php_unit_dedicate_assert``
- =================================
- PHPUnit assertions like ``assertInternalType``, ``assertFileExists``, should be
- used over ``assertTrue``.
- Warning
- -------
- Using this rule is risky
- ~~~~~~~~~~~~~~~~~~~~~~~~
- Fixer could be risky if one is overriding PHPUnit's native methods.
- Configuration
- -------------
- ``target``
- ~~~~~~~~~~
- Target version of PHPUnit.
- Allowed values: ``'3.0'``, ``'3.5'``, ``'5.0'``, ``'5.6'`` and ``'newest'``
- Default value: ``'newest'``
- Examples
- --------
- Example #1
- ~~~~~~~~~~
- *Default* configuration.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- final class MyTest extends \PHPUnit_Framework_TestCase
- {
- public function testSomeTest()
- {
- - $this->assertTrue(is_float( $a), "my message");
- - $this->assertTrue(is_nan($a));
- + $this->assertInternalType('float', $a, "my message");
- + $this->assertNan($a);
- }
- }
- Example #2
- ~~~~~~~~~~
- With configuration: ``['target' => '5.6']``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- final class MyTest extends \PHPUnit_Framework_TestCase
- {
- public function testSomeTest()
- {
- - $this->assertTrue(is_dir($a));
- - $this->assertTrue(is_writable($a));
- - $this->assertTrue(is_readable($a));
- + $this->assertDirectoryExists($a);
- + $this->assertIsWritable($a);
- + $this->assertIsReadable($a);
- }
- }
- Rule sets
- ---------
- The rule is part of the following rule sets:
- - `@PHPUnit30Migration:risky <./../../ruleSets/PHPUnit30MigrationRisky.rst>`_ with config:
- ``['target' => '3.0']``
- - `@PHPUnit32Migration:risky <./../../ruleSets/PHPUnit32MigrationRisky.rst>`_ with config:
- ``['target' => '3.0']``
- - `@PHPUnit35Migration:risky <./../../ruleSets/PHPUnit35MigrationRisky.rst>`_ with config:
- ``['target' => '3.5']``
- - `@PHPUnit43Migration:risky <./../../ruleSets/PHPUnit43MigrationRisky.rst>`_ with config:
- ``['target' => '3.5']``
- - `@PHPUnit48Migration:risky <./../../ruleSets/PHPUnit48MigrationRisky.rst>`_ with config:
- ``['target' => '3.5']``
- - `@PHPUnit50Migration:risky <./../../ruleSets/PHPUnit50MigrationRisky.rst>`_ with config:
- ``['target' => '5.0']``
- - `@PHPUnit52Migration:risky <./../../ruleSets/PHPUnit52MigrationRisky.rst>`_ with config:
- ``['target' => '5.0']``
- - `@PHPUnit54Migration:risky <./../../ruleSets/PHPUnit54MigrationRisky.rst>`_ with config:
- ``['target' => '5.0']``
- - `@PHPUnit55Migration:risky <./../../ruleSets/PHPUnit55MigrationRisky.rst>`_ with config:
- ``['target' => '5.0']``
- - `@PHPUnit56Migration:risky <./../../ruleSets/PHPUnit56MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- - `@PHPUnit57Migration:risky <./../../ruleSets/PHPUnit57MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- - `@PHPUnit60Migration:risky <./../../ruleSets/PHPUnit60MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- - `@PHPUnit75Migration:risky <./../../ruleSets/PHPUnit75MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- - `@PHPUnit84Migration:risky <./../../ruleSets/PHPUnit84MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- - `@PHPUnit91Migration:risky <./../../ruleSets/PHPUnit91MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- - `@PHPUnit100Migration:risky <./../../ruleSets/PHPUnit100MigrationRisky.rst>`_ with config:
- ``['target' => '5.6']``
- References
- ----------
- - Fixer class: `PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitDedicateAssertFixer <./../../../src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php>`_
- - Test class: `PhpCsFixer\\Tests\\Fixer\\PhpUnit\\PhpUnitDedicateAssertFixerTest <./../../../tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php>`_
- The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
|