diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 571333d..aab4991 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,2 @@ parameters: - ignoreErrors: - - - message: '#^Method PhpUnitSplitter\\TestMapper\:\:getMap\(\) should return array\\> but returns array\\>\|string\>\>\.$#' - identifier: return.type - count: 1 - path: src/TestMapper.php + ignoreErrors: [] diff --git a/src/SplitterCommand.php b/src/SplitterCommand.php index 1efea96..46a8c32 100644 --- a/src/SplitterCommand.php +++ b/src/SplitterCommand.php @@ -12,6 +12,8 @@ /** * A symfony command for splitting PHPUnit tests. + * + * @phpstan-import-type TestMap from TestMapper */ class SplitterCommand extends Command { @@ -102,14 +104,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * Splits the tests map into the given number of splits. * - * @param array> $map + * @param TestMap $map * The map of tests. * @param int $splits * The number of splits. * @param int $index * The index of the current split. * - * @return array> + * @return TestMap * The split map. */ private function split(array $map, int $splits, int $index): array { diff --git a/src/TestMapper.php b/src/TestMapper.php index 2045332..9c4604c 100644 --- a/src/TestMapper.php +++ b/src/TestMapper.php @@ -6,6 +6,10 @@ /** * Generates a map of test methods with their file name and execution time. + * + * @phpstan-type TestCaseTime array{testCase: string, time: float} + * @phpstan-type TestClassEntry array{className: string, time: float, testCases: list} + * @phpstan-type TestMap array */ final class TestMapper { @@ -31,7 +35,7 @@ public function __construct( /** * Returns a map of test methods with their file name and execution time. * - * @return array> + * @return TestMap * The map of test files and execution times. */ public function getMap(): array { @@ -51,10 +55,8 @@ public function getMap(): array { if (\str_starts_with($filename, $this->prefix)) { $filename = \substr($filename, \strlen($this->prefix)); } - $map[$filename] = [ - 'className' => $className, - 'time' => 0.0, - ]; + $totalTime = 0.0; + $testCaseTimes = []; $testCases = $class->xpath('testCaseMethod'); foreach ($testCases as $testCase) { $shortName = (string) $testCase->attributes()['name']; @@ -66,12 +68,17 @@ public function getMap(): array { $shortName .= "@$dataSet"; } $time = $this->resultCache->getTime($cacheKey); - $map[$filename]['testCases'][] = [ + $testCaseTimes[] = [ 'testCase' => $shortName, 'time' => $time, ]; - $map[$filename]['time'] += $time; + $totalTime += $time; } + $map[$filename] = [ + 'className' => $className, + 'time' => $totalTime, + 'testCases' => $testCaseTimes, + ]; } return $map; } @@ -79,10 +86,10 @@ public function getMap(): array { /** * Sorts the map by execution time. * - * @param array> $map + * @param TestMap $map * The map to sort. * - * @return array> + * @return TestMap * The sorted map. */ public function sortMap(array $map): array {