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 @@ -32,10 +32,10 @@ final class ArrayKeyExists extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function (array $args): bool {
->with($this->callback(function (array $args): void {
$this->assertArrayHasKey(5, $args);
$this->assertInstanceOf(\stdClass::class, $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ final class ArrowWithClassVariable extends TestCase
$this->createMock('SomeType')
->method('someMethod')
->with($this->callback(
function ($item) use ($type): bool {
function ($item) use ($type): void {
$this->assertInstanceOf($type, $item);
$this->assertSame('name', $item->getName());
return true;
return;
}
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ final class AssertMethodCallTrue extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function ($arg): bool {
->with($this->callback(function ($arg): void {
$this->assertInstanceOf(\Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\WithCallbackIdenticalToStandaloneAssertsRector\Source\SomeClassWithMethodCall::class, $arg);
$this->assertTrue($arg->isReady());
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ final class ClosureInstanceOf extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function ($args): bool {
->with($this->callback(function ($args): void {
$this->assertCount(5, $args);
$this->assertInstanceOf(\stdClass::class, $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ final class CoverEqual extends TestCase
$this->createMock('SomeType')
->method('someMethod')
->with($this->callback(
function ($item) use ($type): bool {
function ($item) use ($type): void {
$this->assertInstanceOf($type, $item);
$this->assertEquals('name', $item->getName());
return true;
return;
}
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ final class ExtraStmt extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function ($args): bool {
->with($this->callback(function ($args): void {
$item = 100;
$this->assertCount(5, $args);
$this->assertArrayHasKey(0, $args);
$this->assertSame('some_value', $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ final class HandleSoloCompare extends TestCase
->method('trans')
->with(
$this->callback(
function ($args): bool {
function ($args): void {
$this->assertCount(5, $args);
return true;
return;
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ final class HandleSoloInstance extends TestCase
->method('trans')
->with(
$this->callback(
function ($arg): bool {
function ($arg): void {
$this->assertInstanceOf(\stdClass::class, $arg);
return true;
return;
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ final class HandleSoloIsset extends TestCase
->method('trans')
->with(
$this->callback(
function ($args): bool {
function ($args): void {
$this->assertArrayHasKey('key', $args);
return true;
return;
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ final class IncludeNoArgs extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function (): bool {
->with($this->callback(function (): void {
$args= [1, 2, 3];
$this->assertCount(5, $args);
$this->assertSame('some_value', $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ final class IssetArrayKeys extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function ($args): bool {
->with($this->callback(function ($args): void {
$this->assertCount(5, $args);
$this->assertArrayHasKey(0, $args);
$this->assertSame('some_value', $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ final class MultiCallbacks extends TestCase
$someMock->expects($this->any())
->method('trans')
->with(
$this->callback(function (array $args): bool {
$this->callback(function (array $args): void {
$this->assertArrayHasKey(5, $args);
return true;
return;
}),
$this->callback(function (array $args): bool {
$this->callback(function (array $args): void {
$this->assertArrayHasKey(50, $args);
return true;
return;
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ final class OnSelf extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function ($arg): bool {
->with($this->callback(function ($arg): void {
$this->assertInstanceOf(self::class, $arg);
$this->assertTrue($arg->isReady());
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ final class OnStaticClosure extends TestCase
$this->createMock('SomeClass')
->expects($this->once())
->method('someMethod')
->with($this->callback(static function (array $args): bool {
->with($this->callback(static function (array $args): void {
self::assertCount(2, $args);
self::assertSame('correct', $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ final class SkipThis extends TestCase
$someMock->expects($this->any())
->method('trans')
->with(
$this->callback(function ($args): bool {
$this->callback(function ($args): void {
$this->assertCount(5, $args);
$this->assertSame($this->expectedValue, $args[0]);
return true;
return;
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ final class UseVariable extends TestCase
$someMock->expects($this->any())
->method('trans')
->with(
$this->callback(function ($args) use ($expectedValue): bool {
$this->callback(function ($args) use ($expectedValue): void {
$this->assertCount(5, $args);
$this->assertSame($expectedValue, $args[0]);
return true;
return;
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ final class UseVariableRequireOnce extends TestCase
$someMock->expects($this->any())
->method('trans')
->with(
$this->callback(function ($args) use ($expectedValue): bool {
$this->callback(function ($args) use ($expectedValue): void {
$this->assertCount(5, $args);
$this->assertSame($expectedValue, $args[0]);
$this->assertSame($expectedValue, $args[2]);
return true;
return;
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ final class WithArrowFunction extends TestCase
->method('trans')
->with(
$this->callback(
function ($args): bool {
function ($args): void {
$this->assertCount(5, $args);
$this->assertInstanceOf(\stdClass::class, $args[0]);
return true;
return;
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ final class WithCallbackAssert extends TestCase

$someMock->expects($this->any())
->method('trans')
->with($this->callback(function ($args): bool {
->with($this->callback(function ($args): void {
$this->assertCount(5, $args);
$this->assertSame('some_value', $args[0]);
return true;
return;
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public function test()
$this->createMock('SomeClass')
->expects($this->once())
->method('someMethod')
->with($this->callback(function (array $args): bool {
->with($this->callback(function (array $args): void {
$this->assertCount(2, $args);
$this->assertSame('correct', $args[0]);

return true;
return;
}));
}
}
Expand Down Expand Up @@ -135,11 +135,12 @@ public function refactor(Node $node): MethodCall|null

$nonReturnCallbackStmts = $this->resolveNonReturnCallbackStmts($argAndFunctionLike);

// last si return true;
$assertExprStmts[] = new Return_($this->nodeFactory->createTrue());
// last is a bare "return;"
$assertExprStmts[] = new Return_();

if ($innerFunctionLike instanceof Closure) {
$innerFunctionLike->stmts = array_merge($nonReturnCallbackStmts, $assertExprStmts);
$innerFunctionLike->returnType = new Identifier('void');
} else {
// arrow function -> flip to closure
$functionLikeInArg = $argAndFunctionLike->getArg();
Expand Down Expand Up @@ -280,7 +281,7 @@ private function createClosure(
'params' => $argAndFunctionLike->getFunctionLike()
->params,
'stmts' => $assertExprStmts,
'returnType' => new Identifier('bool'),
'returnType' => new Identifier('void'),
'uses' => $externalVariables,
]);
}
Expand Down
Loading