diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/closure_instance_of.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/closure_instance_of.php.inc index 261a9c15..b104bfb0 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/closure_instance_of.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/closure_instance_of.php.inc @@ -34,9 +34,10 @@ final class ClosureInstanceOf extends TestCase $someMock->expects($this->any()) ->method('trans') - ->with($this->callback(function ($args): void { + ->with($this->callback(function ($args): bool { $this->assertCount(5, $args); $this->assertInstanceOf(\stdClass::class, $args[0]); + return true; })); } } diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/isset_array_keys.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/isset_array_keys.php.inc index 268280c4..90d80db3 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/isset_array_keys.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/isset_array_keys.php.inc @@ -34,10 +34,11 @@ final class IssetArrayKeys extends TestCase $someMock->expects($this->any()) ->method('trans') - ->with($this->callback(function ($args): void { + ->with($this->callback(function ($args): bool { $this->assertCount(5, $args); $this->assertArrayHasKey(0, $args); $this->assertSame('some_value', $args[0]); + return true; })); } } diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/skip_this.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/skip_this.php.inc index c895911b..e49c3c3e 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/skip_this.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/skip_this.php.inc @@ -44,6 +44,7 @@ final class SkipThis extends TestCase $this->callback(function ($args): void { $this->assertCount(5, $args); $this->assertSame($this->expectedValue, $args[0]); + return true; }) ); } diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable.php.inc index f093fef2..8c605c71 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable.php.inc @@ -40,6 +40,7 @@ final class UseVariable extends TestCase $this->callback(function ($args) use ($expectedValue): void { $this->assertCount(5, $args); $this->assertSame($expectedValue, $args[0]); + return true; }) ); } diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable_require_once.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable_require_once.php.inc index 50959f19..54f831d5 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable_require_once.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable_require_once.php.inc @@ -41,6 +41,7 @@ final class UseVariableRequireOnce extends TestCase $this->assertCount(5, $args); $this->assertSame($expectedValue, $args[0]); $this->assertSame($expectedValue, $args[2]); + return true; }) ); } diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_arrow_function.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_arrow_function.php.inc index f6262a3e..57a1b32e 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_arrow_function.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_arrow_function.php.inc @@ -41,6 +41,7 @@ final class WithArrowFunction extends TestCase function ($args): void { $this->assertCount(5, $args); $this->assertInstanceOf(\stdClass::class, $args[0]); + return true; } ) ); diff --git a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_callback_assert.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_callback_assert.php.inc index f7372c78..ad2b9561 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_callback_assert.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_callback_assert.php.inc @@ -34,9 +34,10 @@ final class WithCallbackAssert extends TestCase $someMock->expects($this->any()) ->method('trans') - ->with($this->callback(function ($args): void { + ->with($this->callback(function ($args): bool { $this->assertCount(5, $args); $this->assertSame('some_value', $args[0]); + return true; })); } } diff --git a/rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php b/rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php index 701b7b64..63b9caab 100644 --- a/rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php +++ b/rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php @@ -51,7 +51,7 @@ public function test() $this->createMock('SomeClass') ->expects($this->once()) ->method('someMethod') - ->with($this->callback(function ($args): bool { + ->with($this->callback(function (array $args): bool { return count($args) === 2 && $args[0] === 'correct' })); } @@ -68,9 +68,11 @@ public function test() $this->createMock('SomeClass') ->expects($this->once()) ->method('someMethod') - ->with($this->callback(function ($args) { + ->with($this->callback(function (array $args): bool { $this->assertCount(2, $args); $this->assertSame('correct', $args[0]); + + return true; })); } } @@ -125,11 +127,13 @@ public function refactor(Node $node): MethodCall|null return null; } + // last si return true; + $assertExpressions[] = new Return_($this->nodeFactory->createTrue()); + $innerFunctionLike = $argAndFunctionLike->getFunctionLike(); if ($innerFunctionLike instanceof Closure) { $innerFunctionLike->stmts = $assertExpressions; - $innerFunctionLike->returnType = new Identifier('void'); } else { // arrow function -> flip to closure $functionLikeInArg = $argAndFunctionLike->getArg();