MergeWithCallableAndWillReturnRector

Merge split mocking method ->with($this->callback(...)) and ->willReturn(expr) to single ->willReturnCallback() call

 use PHPUnit\Framework\TestCase;

 final class SomeTest extends TestCase
 {
     public function test()
     {
         $this->createMock('SomeClass')
             ->expects($this->once())
             ->method('someMethod')
-            ->with($this->callback(function (array $args): bool {
-                return true;
-            }))
-            ->willReturn(['some item']);
+            ->willReturnCallback(function (array $args): array {
+                return ['some item'];
+            });
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\MergeWithCallableAndWillReturnRector;

return RectorConfig::configure()
    ->withRules([
        MergeWithCallableAndWillReturnRector::class,
    ]);
SETS:  Code Quality