Add return type to closures narrowed by assertInstanceOf() inside PHPUnit test case classes
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
public function test()
{
- $callback = function (object $object) {
+ $callback = function (object $object): SomeType {
$this->assertInstanceOf(SomeType::class, $object);
return $object;
};
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeFromAssertInstanceOfRector;
return RectorConfig::configure()
->withRules([
ClosureReturnTypeFromAssertInstanceOfRector::class,
]);