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.
--- 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'].
--- 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:
@PHPUnit3x0Migration:risky with config:
['target' => '3.0']@PHPUnit3x2Migration:risky with config:
['target' => '3.0']@PHPUnit3x5Migration:risky with config:
['target' => '3.5']@PHPUnit4x3Migration:risky with config:
['target' => '3.5']@PHPUnit4x8Migration:risky with config:
['target' => '3.5']@PHPUnit5x0Migration:risky with config:
['target' => '5.0']@PHPUnit5x2Migration:risky with config:
['target' => '5.0']@PHPUnit5x4Migration:risky with config:
['target' => '5.0']@PHPUnit5x5Migration:risky with config:
['target' => '5.0']@PHPUnit5x6Migration:risky with config:
['target' => '5.6']@PHPUnit5x7Migration:risky with config:
['target' => '5.6']@PHPUnit6x0Migration:risky with config:
['target' => '5.6']@PHPUnit7x5Migration:risky with config:
['target' => '5.6']@PHPUnit8x4Migration:risky with config:
['target' => '5.6']@PHPUnit9x1Migration:risky with config:
['target' => '5.6']@PHPUnit10x0Migration:risky with config:
['target' => '5.6']@PHPUnit30Migration:risky (deprecated) with config:
['target' => '3.0']@PHPUnit32Migration:risky (deprecated) with config:
['target' => '3.0']@PHPUnit35Migration:risky (deprecated) with config:
['target' => '3.5']@PHPUnit43Migration:risky (deprecated) with config:
['target' => '3.5']@PHPUnit48Migration:risky (deprecated) with config:
['target' => '3.5']@PHPUnit50Migration:risky (deprecated) with config:
['target' => '5.0']@PHPUnit52Migration:risky (deprecated) with config:
['target' => '5.0']@PHPUnit54Migration:risky (deprecated) with config:
['target' => '5.0']@PHPUnit55Migration:risky (deprecated) with config:
['target' => '5.0']@PHPUnit56Migration:risky (deprecated) with config:
['target' => '5.6']@PHPUnit57Migration:risky (deprecated) with config:
['target' => '5.6']@PHPUnit60Migration:risky (deprecated) with config:
['target' => '5.6']@PHPUnit75Migration:risky (deprecated) with config:
['target' => '5.6']@PHPUnit84Migration:risky (deprecated) with config:
['target' => '5.6']@PHPUnit91Migration:risky (deprecated) with config:
['target' => '5.6']@PHPUnit100Migration:risky (deprecated) with config:
['target' => '5.6']
References¶
Fixer class: PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer
Test class: PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitDedicateAssertFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.