-
Notifications
You must be signed in to change notification settings - Fork 63
[code-quality] Add MatchAssertSameExpectedTypeRector #510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertSame', 'assertEquals'])) { | ||
| return null; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add check:
isFirstClassCallable()count($node->getArgs()) >= 2
I will apply patch for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| $variableExpr = $node->getArgs()[1] | ||
| ->value; | ||
| $variableType = $this->getType($variableExpr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be getNativeType(), avoid compare invalid doc:
public function run()
{
$this->assertSame('123', $this->getOrderId());
}
/**
* @return int
*/
private function getOrderId()
{
return '123';
}I will apply patch for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public function run() | ||
| { | ||
| $this->assertSame('123', $this->getOrderId()); | ||
| } | ||
|
|
||
| private function getOrderId(): int | ||
| { | ||
| return 123; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomasVotruba on assertSame, it actually already error on the first usage before its transformation, that means the test already invalid on very beginning:
There was 1 failure:
1) ArrayLookup\Tests\CollectorTest::test
Failed asserting that 123 is identical to '123'.
so it probably should only apply on assertEquals ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomasVotruba I tested in our project, it cause error:
- $this->assertEquals(1, $this->getOrderId());
+ $this->assertSame('1', $this->getOrderId);that compare:
-'1'
+'00000000000000000001'
this should indeed only on assertEquals, assertSame is apply on actual same type, I will create a patch to only apply on assertEquals and rename the rule to:
-MatchAssertSameExpectedTypeRector
+MatchAssertEqualsExpectedTypeRectorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add test fixture here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| if ($expectedType->isLiteralString()->yes() && $directVariableType->isInteger()->yes()) { | ||
| // update expected type to provided type | ||
| $expectedArg->value = new LNumber((int) $expectedArg->value->value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LNumber is deprecated, use Int_ instead, I will create new PR for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.