Add use Rector\Config\RectorConfig; use Rector\PHPUnit\Rector\Class_\ArrayArgumentToDataProviderRector; use Rector\PHPUnit\ValueObject\ArrayArgumentToDataProvider; return static function (RectorConfig $rectorConfig): void { $rectorConfig->ruleWithConfiguration(ArrayArgumentToDataProviderRector::class, [ ArrayArgumentToDataProviderRector::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => [ new ArrayArgumentToDataProvider('PHPUnit\Framework\TestCase', 'doTestMultiple', 'doTestSingle', 'number'), ], ]); };9 annotation test of the class for faster jump to test. Make it FQN, so it stays in the annotation, not in the PHP source code. Show
+/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { } AnnotationWithValueToAttributeRectorChange annotations with value to attribute 🔧configure it!
use Rector\Config\RectorConfig; use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector; use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute; return static function (RectorConfig $rectorConfig): void { $rectorConfig->ruleWithConfiguration( AnnotationWithValueToAttributeRector::class, [new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\Framework\Attributes\BackupGlobals', [ true, false, ])] ); }; ↓ use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\BackupGlobals; -/** - * @backupGlobals enabled - */ +#[BackupGlobals(true)] final class SomeTest extends TestCase { } ArrayArgumentToDataProviderRectorMove array argument from tests into data provider [configurable] 🔧configure it!
use Rector\Config\RectorConfig; use Rector\PHPUnit\Rector\Class_\ArrayArgumentToDataProviderRector; use Rector\PHPUnit\ValueObject\ArrayArgumentToDataProvider; return static function (RectorConfig $rectorConfig): void { $rectorConfig->ruleWithConfiguration(ArrayArgumentToDataProviderRector::class, [ ArrayArgumentToDataProviderRector::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => [ new ArrayArgumentToDataProvider('PHPUnit\Framework\TestCase', 'doTestMultiple', 'doTestSingle', 'number'), ], ]); }; ↓ use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { - public function test() + /** + * @dataProvider provideData() + */ + public function test(int $number) { - $this->doTestMultiple([1, 2, 3]); + $this->doTestSingle($number); + } + + public function provideData(): \Iterator + { + yield [1]; + yield [2]; + yield [3]; } } AssertCompareToSpecificMethodRectorTurns vague php-only method in PHPUnit TestCase to more specific
-$this->assertSame(10, count($anything), "message"); +$this->assertCount(10, $anything, "message"); -$this->assertNotEquals(get_class($value), SomeInstance::class); +$this->assertNotInstanceOf(SomeInstance::class, $value); AssertComparisonToSpecificMethodRectorTurns comparison operations to their method name alternatives in PHPUnit TestCase
-$this->assertTrue($foo === $bar, "message"); +$this->assertSame($bar, $foo, "message"); use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }0 AssertEqualsParameterToSpecificMethodsTypeRectorChange use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { - public function test() + /** + * @dataProvider provideData() + */ + public function test(int $number) { - $this->doTestMultiple([1, 2, 3]); + $this->doTestSingle($number); + } + + public function provideData(): \Iterator + { + yield [1]; + yield [2]; + yield [3]; } }5 method parameters to new specific alternatives
use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }1 AssertEqualsToSameRectorTurns use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { - public function test() + /** + * @dataProvider provideData() + */ + public function test(int $number) { - $this->doTestMultiple([1, 2, 3]); + $this->doTestSingle($number); + } + + public function provideData(): \Iterator + { + yield [1]; + yield [2]; + yield [3]; } }7 into stricter use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { - public function test() + /** + * @dataProvider provideData() + */ + public function test(int $number) { - $this->doTestMultiple([1, 2, 3]); + $this->doTestSingle($number); + } + + public function provideData(): \Iterator + { + yield [1]; + yield [2]; + yield [3]; } }8 for scalar values in PHPUnit TestCase
use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }2 AssertFalseStrposToContainsRectorTurns -$this->assertSame(10, count($anything), "message"); +$this->assertCount(10, $anything, "message");0/ -$this->assertSame(10, count($anything), "message"); +$this->assertCount(10, $anything, "message");1 comparisons to their method name alternatives in PHPUnit TestCase
use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }3 AssertInstanceOfComparisonRectorTurns instanceof comparisons to their method name alternatives in PHPUnit TestCase
use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }4 use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }5 AssertIssetToSpecificMethodRectorTurns isset comparisons to their method name alternatives in PHPUnit TestCase
use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }6 use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }7 AssertNotOperatorRectorTurns not-operator comparisons to their method name alternatives in PHPUnit TestCase
use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }8 use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; final class ExampleTest extends TestCase { + use ProphecyTrait; + public function testOne(): void { $prophecy = $this->prophesize(\AnInterface::class); } }9 AssertPropertyExistsRectorTurns -$this->assertSame(10, count($anything), "message"); +$this->assertCount(10, $anything, "message");6 comparisons to their method name alternatives in PHPUnit TestCase
+/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }0 AssertRegExpRectorTurns -$this->assertSame(10, count($anything), "message"); +$this->assertCount(10, $anything, "message");8 comparisons to their method name alternatives in PHPUnit TestCase
+/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }1 +/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }2 AssertResourceToClosedResourceRectorTurns -$this->assertNotEquals(get_class($value), SomeInstance::class); +$this->assertNotInstanceOf(SomeInstance::class, $value);0 into stricter -$this->assertNotEquals(get_class($value), SomeInstance::class); +$this->assertNotInstanceOf(SomeInstance::class, $value);1 for resource values in PHPUnit TestCase
+/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }3 AssertSameBoolNullToSpecificMethodRectorTurns same bool and null comparisons to their method name alternatives in PHPUnit TestCase
+/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }4 +/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }5 AssertSameTrueFalseToAssertTrueFalseRectorChange -$this->assertNotEquals(get_class($value), SomeInstance::class); +$this->assertNotInstanceOf(SomeInstance::class, $value);4 ...) to -$this->assertNotEquals(get_class($value), SomeInstance::class); +$this->assertNotInstanceOf(SomeInstance::class, $value);5
+/** + * @see \SomeServiceTest + */ class SomeService { } use PHPUnit\Framework\TestCase; class SomeServiceTest extends TestCase { }6 AssertTrueFalseInternalTypeToSpecificMethodRectorTurns true/false with internal type comparisons to their method name alternatives in PHPUnit TestCase |