function TestResultCollector::testMethodsGroupedByClass
@psalm-return array<string, TestResultCollection>
File
-
vendor/
phpunit/ phpunit/ src/ Logging/ TestDox/ TestResult/ TestResultCollector.php, line 79
Class
- TestResultCollector
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Logging\TestDoxCode
public function testMethodsGroupedByClass() : array {
$result = [];
foreach ($this->tests as $prettifiedClassName => $tests) {
$testsByDeclaringClass = [];
foreach ($tests as $test) {
$declaringClassName = (new ReflectionMethod($test->test()
->className(), $test->test()
->methodName()))
->getDeclaringClass()
->getName();
if (!isset($testsByDeclaringClass[$declaringClassName])) {
$testsByDeclaringClass[$declaringClassName] = [];
}
$testsByDeclaringClass[$declaringClassName][] = $test;
}
foreach (array_keys($testsByDeclaringClass) as $declaringClassName) {
usort($testsByDeclaringClass[$declaringClassName], static function (TestDoxTestMethod $a, TestDoxTestMethod $b) : int {
return $a->test()
->line() <=> $b->test()
->line();
});
}
uksort($testsByDeclaringClass, static function (string $a, string $b) : int {
if (is_subclass_of($b, $a)) {
return -1;
}
if (is_subclass_of($a, $b)) {
return 1;
}
return 0;
});
$tests = [];
foreach ($testsByDeclaringClass as $_tests) {
$tests = array_merge($tests, $_tests);
}
$result[$prettifiedClassName] = TestResultCollection::fromArray($tests);
}
ksort($result);
return $result;
}