Skip to content

Commit 5a2aeca

Browse files
authored
always return true, as required by contract (#571)
1 parent 5861458 commit 5a2aeca

File tree

8 files changed

+17
-6
lines changed

8 files changed

+17
-6
lines changed

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/closure_instance_of.php.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ final class ClosureInstanceOf extends TestCase
3434

3535
$someMock->expects($this->any())
3636
->method('trans')
37-
->with($this->callback(function ($args): void {
37+
->with($this->callback(function ($args): bool {
3838
$this->assertCount(5, $args);
3939
$this->assertInstanceOf(\stdClass::class, $args[0]);
40+
return true;
4041
}));
4142
}
4243
}

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/isset_array_keys.php.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ final class IssetArrayKeys extends TestCase
3434

3535
$someMock->expects($this->any())
3636
->method('trans')
37-
->with($this->callback(function ($args): void {
37+
->with($this->callback(function ($args): bool {
3838
$this->assertCount(5, $args);
3939
$this->assertArrayHasKey(0, $args);
4040
$this->assertSame('some_value', $args[0]);
41+
return true;
4142
}));
4243
}
4344
}

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/skip_this.php.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ final class SkipThis extends TestCase
4444
$this->callback(function ($args): void {
4545
$this->assertCount(5, $args);
4646
$this->assertSame($this->expectedValue, $args[0]);
47+
return true;
4748
})
4849
);
4950
}

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable.php.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final class UseVariable extends TestCase
4040
$this->callback(function ($args) use ($expectedValue): void {
4141
$this->assertCount(5, $args);
4242
$this->assertSame($expectedValue, $args[0]);
43+
return true;
4344
})
4445
);
4546
}

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/use_variable_require_once.php.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final class UseVariableRequireOnce extends TestCase
4141
$this->assertCount(5, $args);
4242
$this->assertSame($expectedValue, $args[0]);
4343
$this->assertSame($expectedValue, $args[2]);
44+
return true;
4445
})
4546
);
4647
}

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_arrow_function.php.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final class WithArrowFunction extends TestCase
4141
function ($args): void {
4242
$this->assertCount(5, $args);
4343
$this->assertInstanceOf(\stdClass::class, $args[0]);
44+
return true;
4445
}
4546
)
4647
);

rules-tests/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector/Fixture/with_callback_assert.php.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ final class WithCallbackAssert extends TestCase
3434

3535
$someMock->expects($this->any())
3636
->method('trans')
37-
->with($this->callback(function ($args): void {
37+
->with($this->callback(function ($args): bool {
3838
$this->assertCount(5, $args);
3939
$this->assertSame('some_value', $args[0]);
40+
return true;
4041
}));
4142
}
4243
}

rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function test()
5151
$this->createMock('SomeClass')
5252
->expects($this->once())
5353
->method('someMethod')
54-
->with($this->callback(function ($args): bool {
54+
->with($this->callback(function (array $args): bool {
5555
return count($args) === 2 && $args[0] === 'correct'
5656
}));
5757
}
@@ -68,9 +68,11 @@ public function test()
6868
$this->createMock('SomeClass')
6969
->expects($this->once())
7070
->method('someMethod')
71-
->with($this->callback(function ($args) {
71+
->with($this->callback(function (array $args): bool {
7272
$this->assertCount(2, $args);
7373
$this->assertSame('correct', $args[0]);
74+
75+
return true;
7476
}));
7577
}
7678
}
@@ -125,11 +127,13 @@ public function refactor(Node $node): MethodCall|null
125127
return null;
126128
}
127129

130+
// last si return true;
131+
$assertExpressions[] = new Return_($this->nodeFactory->createTrue());
132+
128133
$innerFunctionLike = $argAndFunctionLike->getFunctionLike();
129134

130135
if ($innerFunctionLike instanceof Closure) {
131136
$innerFunctionLike->stmts = $assertExpressions;
132-
$innerFunctionLike->returnType = new Identifier('void');
133137
} else {
134138
// arrow function -> flip to closure
135139
$functionLikeInArg = $argAndFunctionLike->getArg();

0 commit comments

Comments
 (0)