From 1c0cc1097f73b60a5ee8d4017531f63ae0677c37 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 3 Sep 2023 10:23:25 +0200 Subject: [PATCH] Closes #5498 --- ChangeLog-10.3.md | 1 + src/Util/Reflection.php | 14 ++++++++++---- tests/end-to-end/regression/5498.phpt | 2 -- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog-10.3.md b/ChangeLog-10.3.md index 47036387a4d..add1e3843f7 100644 --- a/ChangeLog-10.3.md +++ b/ChangeLog-10.3.md @@ -8,6 +8,7 @@ All notable changes of the PHPUnit 10.3 release series are documented in this fi * [#5484](https://github.com/sebastianbergmann/phpunit/issues/5484): TestDox name prettifier only supports backed enumerations * [#5487](https://github.com/sebastianbergmann/phpunit/issues/5487): Tests are run more than once if `` has overlapping ``s +* [#5498](https://github.com/sebastianbergmann/phpunit/issues/5498): Hook methods are run in wrong order ## [10.3.2] - 2023-08-15 diff --git a/src/Util/Reflection.php b/src/Util/Reflection.php index 4aeec4938f8..421fac47fbf 100644 --- a/src/Util/Reflection.php +++ b/src/Util/Reflection.php @@ -52,7 +52,7 @@ public static function sourceLocationFor(string $className, string $methodName): */ public static function publicMethodsInTestClass(ReflectionClass $class): array { - return self::filterAndSortMethods($class, ReflectionMethod::IS_PUBLIC); + return self::filterAndSortMethods($class, ReflectionMethod::IS_PUBLIC, true); } /** @@ -60,13 +60,13 @@ public static function publicMethodsInTestClass(ReflectionClass $class): array */ public static function methodsInTestClass(ReflectionClass $class): array { - return self::filterAndSortMethods($class, null); + return self::filterAndSortMethods($class, null, false); } /** * @psalm-return list */ - private static function filterAndSortMethods(ReflectionClass $class, ?int $filter): array + private static function filterAndSortMethods(ReflectionClass $class, ?int $filter, bool $sortHighestToLowest): array { $methodsByClass = []; @@ -88,9 +88,15 @@ private static function filterAndSortMethods(ReflectionClass $class, ?int $filte $methodsByClass[$declaringClassName][] = $method; } + $classNames = array_keys($methodsByClass); + + if ($sortHighestToLowest) { + $classNames = array_reverse($classNames); + } + $methods = []; - foreach (array_reverse(array_keys($methodsByClass)) as $className) { + foreach ($classNames as $className) { $methods = array_merge($methods, $methodsByClass[$className]); } diff --git a/tests/end-to-end/regression/5498.phpt b/tests/end-to-end/regression/5498.phpt index a38710bad76..0f398ae7cca 100644 --- a/tests/end-to-end/regression/5498.phpt +++ b/tests/end-to-end/regression/5498.phpt @@ -1,7 +1,5 @@ --TEST-- https://github.com/sebastianbergmann/phpunit/issues/5498 ---XFAIL-- -https://github.com/sebastianbergmann/phpunit/issues/5498 --FILE--