Replaces identical compare in $this->callable() sole return to standalone PHPUnit asserts that show more detailed failure messages
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 count($args) === 2 && $args[0] === 'correct'
+ $this->assertCount(2, $args);
+ $this->assertSame('correct', $args[0]);
+
+ return true;
}));
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\WithCallbackIdenticalToStandaloneAssertsRector;
return RectorConfig::configure()
->withRules([
WithCallbackIdenticalToStandaloneAssertsRector::class,
]);