Find the best Rector rule to solve your problem
Turns method names to new ones.
$someObject = new SomeExampleClass;
-$someObject->oldMethod();
+$someObject->newMethod();
Replaces defined classes by new ones.
namespace App;
-use SomeOldClass;
+use SomeNewClass;
-function someFunction(SomeOldClass $someOldClass): SomeOldClass
+function someFunction(SomeNewClass $someOldClass): SomeNewClass
{
- if ($someOldClass instanceof SomeOldClass) {
- return new SomeOldClass;
+ if ($someOldClass instanceof SomeNewClass) {
+ return new SomeNewClass;
}
}
Remove getMockBuilder() to createMock()
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
- $applicationMock = $this->getMockBuilder('SomeClass')
- ->disableOriginalConstructor()
- ->getMock();
+ $applicationMock = $this->createMock('SomeClass');
}
}
Takes setExpectedException()
2nd and next arguments to own methods in PHPUnit.
use PHPUnit\Framework\TestCase;
class SomeTest extends TestCase
{
public function test()
{
- $this->setExpectedException(SomeException::class, "Message", "CODE");
+ $this->setExpectedException(SomeException::class);
+ $this->expectExceptionMessage('Message');
+ $this->expectExceptionCode('CODE');
}
}
Changes @expectedException annotations to
expectException*()` methods
-/**
- * @expectedException Exception
- * @expectedExceptionMessage Message
- */
public function test()
{
+ $this->expectException('Exception');
+ $this->expectExceptionMessage('Message');
// tested code
}
Tests without assertion will have @doesNotPerformAssertion
use PHPUnit\Framework\TestCase;
class SomeClass extends TestCase
{
+ /**
+ * @doesNotPerformAssertions
+ */
public function test()
{
$nothing = 5;
}
}