From a7273c7f31280917b6ae583bd528eea32c2879c9 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 12 Aug 2026 12:03:07 +0200 Subject: [PATCH] [PHPUnit60] Skip imported PHPUnit assert functions in AddDoesNotPerformAssertionToNonAssertingTestRector --- .../skip_imported_assert_function.php.inc | 20 +++++++++++++ src/NodeAnalyzer/AssertCallAnalyzer.php | 30 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 rules-tests/PHPUnit60/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector/Fixture/skip_imported_assert_function.php.inc 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;