diff --git a/rules-tests/PHPUnit60/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector/Fixture/skip_imported_assert_function.php.inc b/rules-tests/PHPUnit60/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector/Fixture/skip_imported_assert_function.php.inc new file mode 100644 index 00000000..255d1bb6 --- /dev/null +++ b/rules-tests/PHPUnit60/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector/Fixture/skip_imported_assert_function.php.inc @@ -0,0 +1,20 @@ +isAssertMethodCall($node); } + // standalone function assert, e.g. "use function PHPUnit\Framework\assertNotNull;" + if ($node instanceof FuncCall) { + return $this->isAssertFuncCall($node); + } + return false; }); } + private function isAssertFuncCall(FuncCall $funcCall): bool + { + $funcCallName = $this->nodeNameResolver->getName($funcCall); + if (! is_string($funcCallName)) { + return false; + } + + if (! str_starts_with($funcCallName, self::PHPUNIT_FUNCTION_NAMESPACE)) { + return false; + } + + $shortFuncCallName = substr($funcCallName, strlen(self::PHPUNIT_FUNCTION_NAMESPACE)); + + return array_any( + self::ASSERT_METHOD_NAME_PREFIXES, + fn (string $assertMethodNamePrefix): bool => str_starts_with($shortFuncCallName, $assertMethodNamePrefix) + ); + } + private function hasNestedAssertCall(ClassMethod $classMethod): bool { $currentClassMethod = $classMethod;