File tree Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,11 @@ final class CodeCoverage
134
134
*/
135
135
private $ report ;
136
136
137
+ /**
138
+ * @var bool
139
+ */
140
+ private $ determineBranchCoverage ;
141
+
137
142
/**
138
143
* @throws RuntimeException
139
144
*/
@@ -457,6 +462,23 @@ public function setUnintentionallyCoveredSubclassesWhitelist(array $whitelist):
457
462
$ this ->unintentionallyCoveredSubclassesWhitelist = $ whitelist ;
458
463
}
459
464
465
+ /**
466
+ * Specify whether branch coverage should be processed, if the chosen driver supports branch coverage
467
+ * Branch coverage is only supported for the Xdebug driver, with an xdebug version of >= 2.3.2
468
+ */
469
+ public function setDetermineBranchCoverage (bool $ flag ): void
470
+ {
471
+ if ($ flag ) {
472
+ if ($ this ->driver instanceof Xdebug && \version_compare (\phpversion ('xdebug ' ), '2.3.2 ' , '>= ' )) {
473
+ $ this ->determineBranchCoverage = $ flag ;
474
+ } else {
475
+ throw new RuntimeException ('Branch coverage requires Xdebug version 2.3.2 or newer ' );
476
+ }
477
+ } else {
478
+ $ this ->determineBranchCoverage = false ;
479
+ }
480
+ }
481
+
460
482
/**
461
483
* Determine the priority for a line
462
484
*
Original file line number Diff line number Diff line change @@ -44,4 +44,9 @@ public function start(bool $determineUnusedAndDead = true): void;
44
44
* Stop collection of code coverage information.
45
45
*/
46
46
public function stop (): array ;
47
+
48
+ /**
49
+ * Specify that branch coverage should be included with collected code coverage information.
50
+ */
51
+ public function setDetermineBranchCoverage (bool $ flag ): void ;
47
52
}
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ public function stop(): array
76
76
return $ this ->detectExecutedLines ($ fetchedLines , $ dbgData );
77
77
}
78
78
79
+ /**
80
+ * Specify that branch coverage should be included with collected code coverage information.
81
+ */
82
+ public function setDetermineBranchCoverage (bool $ flag ): void
83
+ {
84
+ throw new RuntimeException ('Branch coverage is not supported in PHPDBG ' );
85
+ }
86
+
79
87
/**
80
88
* Convert phpdbg based data into the format CodeCoverage expects
81
89
*/
Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ final class Xdebug implements Driver
29
29
*/
30
30
private $ filter ;
31
31
32
+ /**
33
+ * @var bool
34
+ */
35
+ private $ determineBranchCoverage = false ;
36
+
32
37
/**
33
38
* @throws RuntimeException
34
39
*/
@@ -54,11 +59,16 @@ public function __construct(Filter $filter = null)
54
59
*/
55
60
public function start (bool $ determineUnusedAndDead = true ): void
56
61
{
62
+ $ flag = 0 ;
63
+
57
64
if ($ determineUnusedAndDead ) {
58
- \xdebug_start_code_coverage (XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
59
- } else {
60
- \xdebug_start_code_coverage ();
65
+ $ flag = XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE ;
66
+ }
67
+
68
+ if ($ this ->determineBranchCoverage ) {
69
+ $ flag |= XDEBUG_CC_BRANCH_CHECK ;
61
70
}
71
+ \xdebug_start_code_coverage ($ flag );
62
72
}
63
73
64
74
/**
@@ -73,6 +83,17 @@ public function stop(): array
73
83
return $ this ->cleanup ($ data );
74
84
}
75
85
86
+ /**
87
+ * Specify that branch coverage should be included with collected code coverage information.
88
+ */
89
+ public function setDetermineBranchCoverage (bool $ flag ): void
90
+ {
91
+ if ($ flag && \version_compare (\phpversion ('xdebug ' ), '2.3.2 ' , '< ' )) {
92
+ throw new RuntimeException ('Branch coverage requires Xdebug 2.3.2 or newer ' );
93
+ }
94
+ $ this ->determineBranchCoverage = $ flag ;
95
+ }
96
+
76
97
private function cleanup (array $ data ): array
77
98
{
78
99
foreach (\array_keys ($ data ) as $ file ) {
You can’t perform that action at this time.
0 commit comments