PHPUnit assertion method calls like ->assertSame(true, $foo)
should be
written with dedicated method like ->assertTrue($foo)
.
Fixer could be risky if one is overriding PHPUnit's native methods.
List of assertion methods to fix.
Allowed values: a subset of ['assertEquals', 'assertNotEquals', 'assertNotSame', 'assertSame']
Default value: ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']
Default configuration.
--- Original
+++ New
<?php
final class FooTest extends \PHPUnit_Framework_TestCase {
public function testSomething() {
- $this->assertEquals(false, $b);
- $this->assertSame(true, $a);
- $this->assertNotEquals(null, $c);
- $this->assertNotSame(null, $d);
+ $this->assertFalse($b);
+ $this->assertTrue($a);
+ $this->assertNotNull($c);
+ $this->assertNotNull($d);
}
}
With configuration: ['assertions' => ['assertSame', 'assertNotSame']]
.
--- Original
+++ New
<?php
final class FooTest extends \PHPUnit_Framework_TestCase {
public function testSomething() {
$this->assertEquals(false, $b);
- $this->assertSame(true, $a);
+ $this->assertTrue($a);
$this->assertNotEquals(null, $c);
- $this->assertNotSame(null, $d);
+ $this->assertNotNull($d);
}
}
The rule is part of the following rule sets:
- Fixer class: PhpCsFixer\Fixer\PhpUnit\PhpUnitConstructFixer
- Test class: PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitConstructFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.