Skip to content

Commit 8db0f5a

Browse files
committed
cover equals
1 parent 14022fb commit 8db0f5a

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\WithCallbackIdenticalToStandaloneAssertsRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class CoverEqual extends TestCase
8+
{
9+
public function test($type)
10+
{
11+
$this->createMock('SomeType')
12+
->method('someMethod')
13+
->with($this->callback(
14+
fn ($item): bool => $item instanceof $type &&
15+
$item->getName() == 'name'
16+
));
17+
}
18+
}
19+
20+
?>
21+
-----
22+
<?php
23+
24+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\WithCallbackIdenticalToStandaloneAssertsRector\Fixture;
25+
26+
use PHPUnit\Framework\TestCase;
27+
28+
final class CoverEqual extends TestCase
29+
{
30+
public function test($type)
31+
{
32+
$this->createMock('SomeType')
33+
->method('someMethod')
34+
->with($this->callback(
35+
function ($item) use ($type): bool {
36+
$this->assertInstanceOf($type, $item);
37+
$this->assertEquals('name', $item->getName());
38+
return true;
39+
}
40+
));
41+
}
42+
}
43+
44+
?>

rules/CodeQuality/NodeFactory/FromBinaryAndAssertExpressionsFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function create(array $exprs): ?array
8484
continue;
8585
}
8686

87-
if ($expr instanceof Identical) {
87+
if ($expr instanceof Identical || $expr instanceof Expr\BinaryOp\Equal) {
8888
if ($expr->left instanceof FuncCall && $this->nodeNameResolver->isName($expr->left, 'count')) {
8989
if ($expr->right instanceof Int_) {
9090
$countedExpr = $expr->left->getArgs()[0]
@@ -107,7 +107,7 @@ public function create(array $exprs): ?array
107107
// create assertSame()
108108
$assertMethodCalls[] = $this->nodeFactory->createMethodCall(
109109
'this',
110-
'assertSame',
110+
$expr instanceof Identical ? 'assertSame' : 'assertEquals',
111111
[$expr->right, $expr->left]
112112
);
113113
} else {

rules/CodeQuality/Rector/MethodCall/WithCallbackIdenticalToStandaloneAssertsRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function refactor(Node $node): MethodCall|null
122122
} elseif ($innerSoleExpr instanceof Identical || $innerSoleExpr instanceof Instanceof_ || $innerSoleExpr instanceof Isset_ || ($innerSoleExpr instanceof FuncCall && $this->isName(
123123
$innerSoleExpr->name,
124124
'array_key_exists'
125-
))) {
125+
)) || $innerSoleExpr instanceof Expr\BinaryOp\Equal) {
126126
$joinedExprs = [$innerSoleExpr];
127127
} else {
128128
return null;

0 commit comments

Comments
 (0)