Skip to content

Commit

Permalink
Closes #5498
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 3, 2023
1 parent a900fe0 commit 1c0cc10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<testsuites>` has overlapping `<directory>`s
* [#5498](https://github.com/sebastianbergmann/phpunit/issues/5498): Hook methods are run in wrong order

## [10.3.2] - 2023-08-15

Expand Down
14 changes: 10 additions & 4 deletions src/Util/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ 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);
}

/**
* @psalm-return list<ReflectionMethod>
*/
public static function methodsInTestClass(ReflectionClass $class): array
{
return self::filterAndSortMethods($class, null);
return self::filterAndSortMethods($class, null, false);
}

/**
* @psalm-return list<ReflectionMethod>
*/
private static function filterAndSortMethods(ReflectionClass $class, ?int $filter): array
private static function filterAndSortMethods(ReflectionClass $class, ?int $filter, bool $sortHighestToLowest): array
{
$methodsByClass = [];

Expand All @@ -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]);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/end-to-end/regression/5498.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5498
--XFAIL--
https://github.com/sebastianbergmann/phpunit/issues/5498
--FILE--
<?php declare(strict_types=1);
$traceFile = tempnam(sys_get_temp_dir(), __FILE__);
Expand Down

0 comments on commit 1c0cc10

Please sign in to comment.