|
15 | 15 | use SebastianBergmann\CodeCoverage\Data\ProcessedClassType; |
16 | 16 | use SebastianBergmann\CodeCoverage\Data\ProcessedMethodType; |
17 | 17 | use SebastianBergmann\CodeCoverage\Data\ProcessedTraitType; |
| 18 | +use SebastianBergmann\CodeCoverage\Test\TestSizes; |
18 | 19 | use SebastianBergmann\CodeCoverage\Util\Percentage; |
19 | 20 |
|
20 | 21 | /** |
|
28 | 29 | * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage |
29 | 30 | * |
30 | 31 | * @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage |
| 32 | + * |
| 33 | + * @phpstan-import-type TestSizeSet from TestSizes |
| 34 | + * @phpstan-import-type TestSizeCounts from TestSizes |
31 | 35 | */ |
32 | 36 | final class NamespaceNode |
33 | 37 | { |
@@ -55,6 +59,21 @@ final class NamespaceNode |
55 | 59 | private int $numMethods = -1; |
56 | 60 | private int $numTestedMethods = -1; |
57 | 61 |
|
| 62 | + /** |
| 63 | + * @var ?TestSizeCounts |
| 64 | + */ |
| 65 | + private ?array $numExecutedLinesByTestSize = null; |
| 66 | + |
| 67 | + /** |
| 68 | + * @var ?TestSizeCounts |
| 69 | + */ |
| 70 | + private ?array $numTestedClassesByTestSize = null; |
| 71 | + |
| 72 | + /** |
| 73 | + * @var ?TestSizeCounts |
| 74 | + */ |
| 75 | + private ?array $numTestedMethodsByTestSize = null; |
| 76 | + |
58 | 77 | public function __construct(string $name, string $namespace, ?self $parent = null) |
59 | 78 | { |
60 | 79 | $this->name = $name; |
@@ -174,6 +193,28 @@ public function numberOfExecutedLines(): int |
174 | 193 | return $this->numExecutedLines; |
175 | 194 | } |
176 | 195 |
|
| 196 | + /** |
| 197 | + * @param TestSizeSet $testSizes |
| 198 | + */ |
| 199 | + public function numberOfExecutedLinesByTestSize(int $testSizes): int |
| 200 | + { |
| 201 | + if ($this->numExecutedLinesByTestSize === null) { |
| 202 | + $this->numExecutedLinesByTestSize = TestSizes::ZERO_COUNTS; |
| 203 | + |
| 204 | + foreach (TestSizes::COMBINATIONS as $combination) { |
| 205 | + foreach ($this->classesInSubtree() as $class) { |
| 206 | + $this->numExecutedLinesByTestSize[$combination] += $class->class_()->executedLinesByTestSize[$combination]; |
| 207 | + } |
| 208 | + |
| 209 | + foreach ($this->traitsInSubtree() as $trait) { |
| 210 | + $this->numExecutedLinesByTestSize[$combination] += $trait->executedLinesByTestSize[$combination]; |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + return $this->numExecutedLinesByTestSize[$testSizes]; |
| 216 | + } |
| 217 | + |
177 | 218 | public function numberOfExecutableBranches(): int |
178 | 219 | { |
179 | 220 | if ($this->numExecutableBranches === -1) { |
@@ -280,6 +321,30 @@ public function numberOfTestedClasses(): int |
280 | 321 | return $this->numTestedClasses; |
281 | 322 | } |
282 | 323 |
|
| 324 | + /** |
| 325 | + * @param TestSizeSet $testSizes |
| 326 | + */ |
| 327 | + public function numberOfTestedClassesByTestSize(int $testSizes): int |
| 328 | + { |
| 329 | + if ($this->numTestedClassesByTestSize === null) { |
| 330 | + $this->numTestedClassesByTestSize = TestSizes::ZERO_COUNTS; |
| 331 | + |
| 332 | + foreach (TestSizes::COMBINATIONS as $combination) { |
| 333 | + foreach ($this->classes as $class) { |
| 334 | + if ($class->numberOfMethods() > 0 && $class->numberOfTestedMethodsByTestSize($combination) === $class->numberOfMethods()) { |
| 335 | + $this->numTestedClassesByTestSize[$combination]++; |
| 336 | + } |
| 337 | + } |
| 338 | + |
| 339 | + foreach ($this->childNamespaces as $ns) { |
| 340 | + $this->numTestedClassesByTestSize[$combination] += $ns->numberOfTestedClassesByTestSize($combination); |
| 341 | + } |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + return $this->numTestedClassesByTestSize[$testSizes]; |
| 346 | + } |
| 347 | + |
283 | 348 | public function numberOfMethods(): int |
284 | 349 | { |
285 | 350 | if ($this->numMethods === -1) { |
@@ -310,6 +375,30 @@ public function numberOfTestedMethods(): int |
310 | 375 | return $this->numTestedMethods; |
311 | 376 | } |
312 | 377 |
|
| 378 | + /** |
| 379 | + * @param TestSizeSet $testSizes |
| 380 | + */ |
| 381 | + public function numberOfTestedMethodsByTestSize(int $testSizes): int |
| 382 | + { |
| 383 | + if ($this->numTestedMethodsByTestSize === null) { |
| 384 | + $this->numTestedMethodsByTestSize = TestSizes::ZERO_COUNTS; |
| 385 | + |
| 386 | + foreach ($this->methodsInSubtree() as $method) { |
| 387 | + if ($method->executableLines === 0) { |
| 388 | + continue; |
| 389 | + } |
| 390 | + |
| 391 | + foreach (TestSizes::COMBINATIONS as $combination) { |
| 392 | + if ($method->executedLinesByTestSize[$combination] === $method->executableLines) { |
| 393 | + $this->numTestedMethodsByTestSize[$combination]++; |
| 394 | + } |
| 395 | + } |
| 396 | + } |
| 397 | + } |
| 398 | + |
| 399 | + return $this->numTestedMethodsByTestSize[$testSizes]; |
| 400 | + } |
| 401 | + |
313 | 402 | public function percentageOfExecutedLines(): Percentage |
314 | 403 | { |
315 | 404 | return Percentage::fromFractionAndTotal( |
@@ -450,5 +539,9 @@ private function resetCounters(): void |
450 | 539 | $this->numTestedClasses = -1; |
451 | 540 | $this->numMethods = -1; |
452 | 541 | $this->numTestedMethods = -1; |
| 542 | + |
| 543 | + $this->numExecutedLinesByTestSize = null; |
| 544 | + $this->numTestedClassesByTestSize = null; |
| 545 | + $this->numTestedMethodsByTestSize = null; |
453 | 546 | } |
454 | 547 | } |
0 commit comments