diff --git a/src/Util/Test.php b/src/Util/Test.php index 639cf0eee39..573fc02f710 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -718,26 +718,30 @@ public static function getHookMethods(string $className): array continue; } - if (self::isBeforeClassMethod($method)) { - \array_unshift( - self::$hookMethods[$className]['beforeClass'], - $method->getName() - ); - } - - if (self::isBeforeMethod($method)) { - \array_unshift( - self::$hookMethods[$className]['before'], - $method->getName() - ); - } + if ($methodComment = $method->getDocComment()) { + if ($method->isStatic()) { + if (\strpos($methodComment, '@beforeClass') !== false) { + \array_unshift( + self::$hookMethods[$className]['beforeClass'], + $method->getName() + ); + } + + if (\strpos($methodComment, '@afterClass') !== false) { + self::$hookMethods[$className]['afterClass'][] = $method->getName(); + } + } - if (self::isAfterMethod($method)) { - self::$hookMethods[$className]['after'][] = $method->getName(); - } + if (\preg_match('/@before\b/', $methodComment) > 0) { + \array_unshift( + self::$hookMethods[$className]['before'], + $method->getName() + ); + } - if (self::isAfterClassMethod($method)) { - self::$hookMethods[$className]['afterClass'][] = $method->getName(); + if (\preg_match('/@after\b/', $methodComment) > 0) { + self::$hookMethods[$className]['after'][] = $method->getName(); + } } } } catch (ReflectionException $e) { @@ -1088,26 +1092,6 @@ private static function resolveReflectionObjectsToLines(array $reflectors): arra return $result; } - private static function isBeforeClassMethod(ReflectionMethod $method): bool - { - return $method->isStatic() && \strpos($method->getDocComment(), '@beforeClass') !== false; - } - - private static function isBeforeMethod(ReflectionMethod $method): bool - { - return \preg_match('/@before\b/', $method->getDocComment()) > 0; - } - - private static function isAfterClassMethod(ReflectionMethod $method): bool - { - return $method->isStatic() && \strpos($method->getDocComment(), '@afterClass') !== false; - } - - private static function isAfterMethod(ReflectionMethod $method): bool - { - return \preg_match('/@after\b/', $method->getDocComment()) > 0; - } - /** * Trims any extensions from version string that follows after * the .[.] format