@@ -54,6 +54,8 @@ class PHP_CodeCoverage
54
54
55
55
/**
56
56
* @var bool
57
+ *
58
+ * @deprecated
57
59
*/
58
60
private $ processUncoveredFilesFromWhitelist = false ;
59
61
@@ -86,6 +88,13 @@ class PHP_CodeCoverage
86
88
*/
87
89
private $ tests = [];
88
90
91
+ /**
92
+ * Store all uncovered files
93
+ *
94
+ * @var array
95
+ */
96
+ private $ uncoveredFiles = array ();
97
+
89
98
/**
90
99
* Constructor.
91
100
*
@@ -105,6 +114,8 @@ public function __construct(PHP_CodeCoverage_Driver $driver = null, PHP_CodeCove
105
114
106
115
$ this ->driver = $ driver ;
107
116
$ this ->filter = $ filter ;
117
+
118
+ $ this ->initData ();
108
119
}
109
120
110
121
/**
@@ -213,7 +224,7 @@ public function start($id, $clear = false)
213
224
214
225
$ this ->currentId = $ id ;
215
226
216
- $ this ->driver ->start ();
227
+ $ this ->driver ->start (false );
217
228
}
218
229
219
230
/**
@@ -244,6 +255,12 @@ public function stop($append = true, $linesToBeCovered = [], array $linesToBeUse
244
255
$ data = $ this ->driver ->stop ();
245
256
$ this ->append ($ data , null , $ append , $ linesToBeCovered , $ linesToBeUsed );
246
257
258
+ foreach (array_keys ($ data ) as $ file ) {
259
+ if (isset ($ this ->uncoveredFiles [$ file ])) {
260
+ unset($ this ->uncoveredFiles [$ file ]);
261
+ }
262
+ }
263
+
247
264
$ this ->currentId = null ;
248
265
249
266
return $ data ;
@@ -566,7 +583,7 @@ private function applyIgnoredLinesFilter(array &$data)
566
583
private function initializeFilesThatAreSeenTheFirstTime (array $ data )
567
584
{
568
585
foreach ($ data as $ file => $ lines ) {
569
- if ($ this ->filter ->isFile ($ file ) && !isset ($ this ->data [$ file ])) {
586
+ if ($ this ->filter ->isFile ($ file ) && !isset ($ this ->data [$ file ]) && ! $ this -> filter ()-> isFiltered ( $ file ) ) {
570
587
$ this ->data [$ file ] = [];
571
588
572
589
foreach ($ lines as $ k => $ v ) {
@@ -581,62 +598,15 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data)
581
598
*/
582
599
private function addUncoveredFilesFromWhitelist ()
583
600
{
584
- $ data = [];
585
- $ uncoveredFiles = array_diff (
586
- $ this ->filter ->getWhitelist (),
587
- array_keys ($ this ->data )
588
- );
601
+ $ data = [];
589
602
590
- foreach ($ uncoveredFiles as $ uncoveredFile ) {
591
- if (!file_exists ($ uncoveredFile )) {
592
- continue ;
593
- }
594
-
595
- if ($ this ->processUncoveredFilesFromWhitelist ) {
596
- $ this ->processUncoveredFileFromWhitelist (
597
- $ uncoveredFile ,
598
- $ data ,
599
- $ uncoveredFiles
600
- );
601
- } else {
602
- $ data [$ uncoveredFile ] = [];
603
-
604
- $ lines = count (file ($ uncoveredFile ));
605
-
606
- for ($ i = 1 ; $ i <= $ lines ; $ i ++) {
607
- $ data [$ uncoveredFile ][$ i ] = PHP_CodeCoverage_Driver::LINE_NOT_EXECUTED ;
608
- }
609
- }
603
+ foreach (array_keys ($ this ->uncoveredFiles ) as $ file ) {
604
+ $ data [$ file ] = $ this ->data [$ file ];
610
605
}
611
606
612
607
$ this ->append ($ data , 'UNCOVERED_FILES_FROM_WHITELIST ' );
613
608
}
614
609
615
- /**
616
- * @param string $uncoveredFile
617
- * @param array $data
618
- * @param array $uncoveredFiles
619
- */
620
- private function processUncoveredFileFromWhitelist ($ uncoveredFile , array &$ data , array $ uncoveredFiles )
621
- {
622
- $ this ->driver ->start ();
623
- include_once $ uncoveredFile ;
624
- $ coverage = $ this ->driver ->stop ();
625
-
626
- foreach ($ coverage as $ file => $ fileCoverage ) {
627
- if (!isset ($ data [$ file ]) &&
628
- in_array ($ file , $ uncoveredFiles )) {
629
- foreach (array_keys ($ fileCoverage ) as $ key ) {
630
- if ($ fileCoverage [$ key ] == PHP_CodeCoverage_Driver::LINE_EXECUTED ) {
631
- $ fileCoverage [$ key ] = PHP_CodeCoverage_Driver::LINE_NOT_EXECUTED ;
632
- }
633
- }
634
-
635
- $ data [$ file ] = $ fileCoverage ;
636
- }
637
- }
638
- }
639
-
640
610
/**
641
611
* Returns the lines of a source file that should be ignored.
642
612
*
@@ -909,4 +879,22 @@ private function selectDriver()
909
879
return new PHP_CodeCoverage_Driver_Xdebug ;
910
880
}
911
881
}
882
+
883
+ /**
884
+ * Initialise the data with the executable/dead lines from each file in the whitelist
885
+ */
886
+ private function initData ()
887
+ {
888
+ foreach ($ this ->filter ()->getWhitelist () as $ file ) {
889
+ $ this ->driver ->start ();
890
+ include_once ($ file );
891
+ $ data = $ this ->driver ->stop ();
892
+
893
+ $ this ->initializeFilesThatAreSeenTheFirstTime ($ data );
894
+ }
895
+
896
+ foreach (array_keys ($ this ->data ) as $ file ) {
897
+ $ this ->uncoveredFiles [$ file ] = 1 ;
898
+ }
899
+ }
912
900
}
0 commit comments