diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php deleted file mode 100644 index 1a7b0b71..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php +++ /dev/null @@ -1,19 +0,0 @@ -assertEquals($expectedNull, $null); - - $bool = true; - $expectedBool = true; - $this->assertEquals($expectedBool, $bool); - } -} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/assert_same_null.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/assert_same_null.php.inc new file mode 100644 index 00000000..7874bf5c --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/assert_same_null.php.inc @@ -0,0 +1,31 @@ +assertSame($result, null); + $this->assertNotSame($result, false); + } +} + +?> +----- +assertSame(null, $result); + $this->assertNotSame(false, $result); + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/cover_external_static_call.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/cover_external_static_call.php.inc new file mode 100644 index 00000000..b46bac6e --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/cover_external_static_call.php.inc @@ -0,0 +1,33 @@ + +----- + diff --git a/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php b/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php index 64a2e303..d762edb6 100644 --- a/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php +++ b/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ClassConstFetch; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar; @@ -119,6 +120,10 @@ private function isScalarValue(Expr $expr): bool return true; } + if ($expr instanceof ConstFetch) { + return true; + } + return $expr instanceof ClassConstFetch; } } diff --git a/src/Enum/PHPUnitClassName.php b/src/Enum/PHPUnitClassName.php new file mode 100644 index 00000000..51708c6a --- /dev/null +++ b/src/Enum/PHPUnitClassName.php @@ -0,0 +1,18 @@ +isInTestClass($node)) { - return false; + if ($node instanceof MethodCall) { + return $this->isInTestClass($node); + } + + if ($node instanceof StaticCall) { + $classType = $this->nodeTypeResolver->getType($node->class); + if ($classType instanceof ObjectType) { + if ($classType->isInstanceOf(PHPUnitClassName::TEST_CASE)->yes()) { + return true; + } + + if ($classType->isInstanceOf(PHPUnitClassName::ASSERT)->yes()) { + return true; + } + } } - return $node instanceof MethodCall || $node instanceof StaticCall; + return false; } }