From c7987c2c5810a954330ee50eb3729895c0910a33 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Thu, 17 Feb 2022 09:25:43 +0100 Subject: [PATCH] PhpUnitDedicateAssertFixer - Fix more count cases --- src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php | 6 +++++- tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php index 25bbaf9d058..4d999f9f5ba 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php @@ -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; } diff --git a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php index 590c809bc3e..0fad8e4d8f1 100644 --- a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php @@ -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));'), ],