PHPUnit methods like assertSame
should be used instead of assertEquals
.
Risky when any of the functions are overridden or when testing object equality.
List of assertion methods to fix.
Allowed values: a subset of ['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']
Default value: ['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals', 'assertNotEquals']
Default configuration.
--- Original
+++ New
<?php
final class MyTest extends \PHPUnit_Framework_TestCase
{
public function testSomeTest()
{
- $this->assertAttributeEquals(a(), b());
- $this->assertAttributeNotEquals(a(), b());
- $this->assertEquals(a(), b());
- $this->assertNotEquals(a(), b());
+ $this->assertAttributeSame(a(), b());
+ $this->assertAttributeNotSame(a(), b());
+ $this->assertSame(a(), b());
+ $this->assertNotSame(a(), b());
}
}
With configuration: ['assertions' => ['assertEquals']]
.
--- Original
+++ New
<?php
final class MyTest extends \PHPUnit_Framework_TestCase
{
public function testSomeTest()
{
$this->assertAttributeEquals(a(), b());
$this->assertAttributeNotEquals(a(), b());
- $this->assertEquals(a(), b());
+ $this->assertSame(a(), b());
$this->assertNotEquals(a(), b());
}
}
The rule is part of the following rule set:
- Fixer class: PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer
- Test class: PhpCsFixer\Tests\Fixer\PhpUnit\PhpUnitStrictFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.