Skip to content

Commit

Permalink
minor #6292 PhpUnitDedicateAssertFixer - Fix more count cases (SpaceP…
Browse files Browse the repository at this point in the history
…ossum)

This PR was merged into the master branch.

Discussion
----------

PhpUnitDedicateAssertFixer - Fix more count cases

Commits
-------

c7987c2 PhpUnitDedicateAssertFixer - Fix more count cases
  • Loading branch information
SpacePossum committed Feb 17, 2022
2 parents ad4a709 + c7987c2 commit 0999168
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php
Expand Up @@ -379,7 +379,11 @@ private function fixAssertSameEquals(Tokens $tokens, array $assertCall): void
// let $a = [1,2]; $b = "2";
// "$this->assertEquals("2", count($a)); $this->assertEquals($b, count($a)); $this->assertEquals(2.1, count($a));"

if (!$tokens[$expectedIndex]->isGivenKind(T_LNUMBER)) {
if ($tokens[$expectedIndex]->isGivenKind([T_VARIABLE])) {
if (!$tokens[$tokens->getNextMeaningfulToken($expectedIndex)]->equals(',')) {
return;
}
} elseif (!$tokens[$expectedIndex]->isGivenKind([T_LNUMBER, T_VARIABLE])) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php
Expand Up @@ -440,9 +440,13 @@ public function provideTestAssertCountCases(): array
)# 7
;# 8'),
],
'do not fix 1' => [
[
self::generateTest('$this->assertCount($b, $a);'),
self::generateTest('$this->assertSame($b, %s($a));'),
],
'do not fix 1' => [
self::generateTest('$this->assertSame($b[1], %s($a));'),
],
'do not fix 2' => [
self::generateTest('$this->assertSame(b(), %s($a));'),
],
Expand Down

0 comments on commit 0999168

Please sign in to comment.