Find the best Rector rule to solve your problem. Searching through 1011 rules.
Found 13 rules:
Turns strpos/stripos comparisons to their method name alternatives in PHPUnit TestCase
-$this->assertFalse(strpos($anything, "foo"), "message");
+$this->assertNotContains("foo", $anything, "message");
Turns not-operator comparisons to their method name alternatives in PHPUnit TestCase
-$this->assertTrue(!$foo, "message");
+$this->assertFalse($foo, "message");
Replaces use of assertSame and assertEquals on Countable objects with count method
-$this->assertSame(1, $countable->count());
+$this->assertCount(1, $countable);
Turns true/false comparisons to their method name alternatives in PHPUnit TestCase when possible
-$this->assertTrue(is_readable($readmeFile), "message");
+$this->assertIsReadable($readmeFile, "message");
Turns assertEquals() into stricter assertSame() for scalar values in PHPUnit TestCase
-$this->assertEquals(2, $result);
+$this->assertSame(2, $result);
Turns instanceof comparisons to their method name alternatives in PHPUnit TestCase
-$this->assertTrue($foo instanceof Foo, "message");
+$this->assertInstanceOf("Foo", $foo, "message");
Correct expected type in assertSame() method to match strict type of passed variable
use PHPUnit\Framework\TestCase;
class SomeTest extends TestCase
{
public function test()
{
- $this->assertSame('123', $this->getOrderId());
+ $this->assertSame(123, $this->getOrderId());
}
private function getOrderId(): int
{
return 123;
}
}
Change assertNotEmpty() and assertNotNull() on an object to more clear assertInstanceof()
use PHPUnit\Framework\TestCase;
class SomeClass extends TestCase
{
public function test()
{
$someObject = new stdClass();
- $this->assertNotEmpty($someObject);
+ $this->assertInstanceof(stdClass::class, $someObject);
}
}
Turns assertTrue() + isset() comparisons to more precise assertArrayHasKey() method
-$this->assertTrue(isset($anything["foo"]), "message");
+$this->assertArrayHasKey("foo", $anything, "message");
Turns same bool and null comparisons to their method name alternatives in PHPUnit TestCase
-$this->assertSame(null, $anything);
+$this->assertNull($anything);
Turns comparison operations to their method name alternatives in PHPUnit TestCase
-$this->assertTrue($foo === $bar, "message");
+$this->assertSame($bar, $foo, "message");
Change $this->assertSame(true, ...) to assertTrue()
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
$value = (bool) mt_rand(0, 1);
- $this->assertSame(true, $value);
+ $this->assertTrue($value);
}
}
Split object casted to array to assert public properties to standalone assert calls
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestClass
{
public function test()
{
$someObject = new SomeObject();
- $this->assertSame([
- 'name' => 'John',
- 'surname' => 'Doe',
- ], (array) $someObject));
+ $this->assertSame('John', $someObject->name);
+ $this->assertSame('Doe', $someObject->surname);
}
}