@@ -62,7 +62,8 @@ final class CodeCoverage
6262 private ?Timer $ timer = null ;
6363 private bool $ requireCoverageContribution = false ;
6464 private bool $ lastTestContributedToCoverage = false ;
65- private bool $ collectsBranchAndPathCoverage = false ;
65+ private bool $ collectsBranchCoverage = false ;
66+ private bool $ collectsPathCoverage = false ;
6667
6768 public static function instance (): self
6869 {
@@ -81,7 +82,11 @@ public function init(Configuration $configuration, CodeCoverageFilterRegistry $c
8182 return CodeCoverageInitializationStatus::NOT_REQUESTED ;
8283 }
8384
84- $ this ->activate ($ codeCoverageFilterRegistry ->get (), $ configuration ->pathCoverage ());
85+ $ this ->activate (
86+ $ codeCoverageFilterRegistry ->get (),
87+ $ configuration ->branchCoverage (),
88+ $ configuration ->pathCoverage (),
89+ );
8590
8691 if (!$ this ->isActive ()) {
8792 return CodeCoverageInitializationStatus::FAILED ;
@@ -274,15 +279,21 @@ public function lastTestContributedToCoverage(): bool
274279
275280 public function deactivate (): void
276281 {
277- $ this ->driver = null ;
278- $ this ->codeCoverage = null ;
279- $ this ->test = null ;
280- $ this ->collectsBranchAndPathCoverage = false ;
282+ $ this ->driver = null ;
283+ $ this ->codeCoverage = null ;
284+ $ this ->test = null ;
285+ $ this ->collectsBranchCoverage = false ;
286+ $ this ->collectsPathCoverage = false ;
281287 }
282288
283- public function collectsBranchAndPathCoverage (): bool
289+ public function collectsBranchCoverage (): bool
284290 {
285- return $ this ->collectsBranchAndPathCoverage ;
291+ return $ this ->collectsBranchCoverage ;
292+ }
293+
294+ public function collectsPathCoverage (): bool
295+ {
296+ return $ this ->collectsPathCoverage ;
286297 }
287298
288299 public function generateReports (Printer $ printer , Configuration $ configuration ): void
@@ -486,13 +497,26 @@ public function warnIfFilterIsNotConfigured(CodeCoverageFilterRegistry $codeCove
486497 $ this ->deactivate ();
487498 }
488499
489- private function activate (Filter $ filter , bool $ pathCoverage ): void
500+ private function activate (Filter $ filter , bool $ branchCoverage , bool $ pathCoverage ): void
490501 {
491502 try {
503+ $ granularity = Granularity::Line;
504+
505+ if ($ branchCoverage ) {
506+ $ granularity = Granularity::LineAndBranch;
507+ }
508+
492509 if ($ pathCoverage ) {
493510 $ granularity = Granularity::LineBranchAndPath;
494- } else {
495- $ granularity = Granularity::Line;
511+ }
512+
513+ /**
514+ * @todo This needs to be removed once code coverage drivers are supported that can collect branch coverage without path coverage
515+ */
516+ if ($ branchCoverage || $ pathCoverage ) {
517+ $ branchCoverage = true ;
518+ $ pathCoverage = true ;
519+ $ granularity = Granularity::LineBranchAndPath;
496520 }
497521
498522 $ this ->driver = (new Selector )->select ($ filter , $ granularity );
@@ -502,7 +526,8 @@ private function activate(Filter $filter, bool $pathCoverage): void
502526 $ filter ,
503527 );
504528
505- $ this ->collectsBranchAndPathCoverage = $ pathCoverage ;
529+ $ this ->collectsBranchCoverage = $ branchCoverage ;
530+ $ this ->collectsPathCoverage = $ pathCoverage ;
506531 } catch (CodeCoverageException $ e ) {
507532 EventFacade::emitter ()->testRunnerTriggeredPhpunitWarning (
508533 $ e ->getMessage (),
0 commit comments