Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class WithArrowFunction extends TestCase
function ($args): void {
$this->assertCount(5, $args);
$this->assertInstanceOf(\stdClass::class, $args[0]);
return true;
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}));
}
Expand All @@ -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;
}));
}
}
Expand Down Expand Up @@ -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();
Expand Down