@@ -63,12 +63,23 @@ class PHP_CodeCoverage_Report_Text
6363 protected $ title ;
6464 protected $ lowUpperBound ;
6565 protected $ highLowerBound ;
66-
67- public function __construct (PHPUnit_Util_Printer $ outputStream , $ title , $ lowUpperBound , $ highLowerBound ) {
66+ protected $ showUncoveredFiles ;
67+
68+ protected $ colors = array (
69+ 'green ' => "\x1b[30;42m " ,
70+ 'yellow ' => "\x1b[30;43m " ,
71+ 'red ' => "\x1b[37;41m " ,
72+ 'header ' => "\x1b[47;40m " ,
73+ 'reset ' => "\x1b[0m " ,
74+ 'eol ' => "\x1b[2K " ,
75+ );
76+
77+ public function __construct (PHPUnit_Util_Printer $ outputStream , $ title , $ lowUpperBound , $ highLowerBound , $ showUncoveredFiles ) {
6878 $ this ->outputStream = $ outputStream ;
6979 $ this ->title = $ title ;
7080 $ this ->lowUpperBound = $ lowUpperBound ;
7181 $ this ->highLowerBound = $ highLowerBound ;
82+ $ this ->showUncoveredFiles = $ showUncoveredFiles ;
7283 }
7384
7485 /**
@@ -77,27 +88,37 @@ public function __construct(PHPUnit_Util_Printer $outputStream, $title, $lowUppe
7788 * @param string $name
7889 * @return string
7990 */
80- public function process (PHP_CodeCoverage $ coverage , $ colors = false )
91+ public function process (PHP_CodeCoverage $ coverage , $ showColors = false )
8192 {
8293 $ output = "" ;
8394
84- $ output .= PHP_EOL . PHP_EOL . "Code Coverage Report " ;
95+ $ packages = array ();
96+ $ report = $ coverage ->getReport ();
97+ unset($ coverage );
98+
99+ $ colors = array ('header ' => '' , 'classes ' => '' , 'methods ' => '' , 'lines ' => '' , 'reset ' => '' , 'eol ' => '' );
100+ if ($ showColors ) {
101+ $ colors ['classes ' ] = $ this ->getCoverageColor ($ report ->getNumTestedClasses (), $ report ->getNumClasses ());
102+ $ colors ['methods ' ] = $ this ->getCoverageColor ($ report ->getNumTestedMethods (), $ report ->getNumMethods ());
103+ $ colors ['lines ' ] = $ this ->getCoverageColor ($ report ->getNumExecutedLines (), $ report ->getNumExecutableLines ());
104+ $ colors ['reset ' ] = $ this ->colors ['reset ' ];
105+ $ colors ['header ' ] = $ this ->colors ['header ' ];
106+ $ colors ['eol ' ] = $ this ->colors ['eol ' ];
107+ }
108+
109+ $ output .= PHP_EOL . PHP_EOL . $ colors ['header ' ] . "Code Coverage Report " ;
85110 if ($ this ->title ) {
86111 $ output .= 'for " ' . $ this ->title . '" ' ;
87112 }
88113 $ output .= PHP_EOL . date (" Y-m-d H:i:s " , $ _SERVER ['REQUEST_TIME ' ]) . PHP_EOL ;
89114
90- $ packages = array ();
91- $ report = $ coverage ->getReport ();
92- unset($ coverage );
93-
94- $ output .= PHP_EOL . 'Summary: ' . PHP_EOL
95- . ' Classes: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedClasses (), $ report ->getNumClasses (), TRUE )
96- . ' ( ' . $ report ->getNumTestedClasses () . '/ ' . $ report ->getNumClasses () . ' ) ' . PHP_EOL
97- . ' Methods: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedMethods (), $ report ->getNumMethods (), TRUE )
98- . ' ( ' . $ report ->getNumTestedMethods () . '/ ' . $ report ->getNumMethods () . ' ) ' . PHP_EOL
99- . ' Lines: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumExecutedLines (), $ report ->getNumExecutableLines (), TRUE )
100- . ' ( ' . $ report ->getNumExecutedLines () . '/ ' . $ report ->getNumExecutableLines () . ' ) ' . PHP_EOL ;
115+ $ output .= PHP_EOL . ' Summary: ' . PHP_EOL . $ colors ['reset ' ]
116+ . $ colors ['classes ' ] . $ colors ['eol ' ] . ' Classes: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedClasses (), $ report ->getNumClasses (), TRUE )
117+ . ' ( ' . $ report ->getNumTestedClasses () . '/ ' . $ report ->getNumClasses () . ' ) ' . PHP_EOL . $ colors ['reset ' ] . $ colors ['eol ' ]
118+ . $ colors ['methods ' ] . $ colors ['eol ' ] . ' Methods: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedMethods (), $ report ->getNumMethods (), TRUE )
119+ . ' ( ' . $ report ->getNumTestedMethods () . '/ ' . $ report ->getNumMethods () . ' ) ' . PHP_EOL . $ colors ['reset ' ] . $ colors ['eol ' ]
120+ . $ colors ['lines ' ] . $ colors ['eol ' ] . ' Lines: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumExecutedLines (), $ report ->getNumExecutableLines (), TRUE )
121+ . ' ( ' . $ report ->getNumExecutedLines () . '/ ' . $ report ->getNumExecutableLines () . ' ) ' . PHP_EOL . $ colors ['reset ' ] . $ colors ['eol ' ];
101122
102123 foreach ($ report as $ item ) {
103124 if (!$ item instanceof PHP_CodeCoverage_Report_Node_File) {
@@ -163,19 +184,31 @@ public function process(PHP_CodeCoverage $coverage, $colors = false)
163184 }
164185
165186 if (!empty ($ class ['package ' ]['namespace ' ])) {
166- $ namespace = $ class ['package ' ]['namespace ' ];
187+ $ namespace = '\\' . $ class ['package ' ]['namespace ' ] . ':: ' ;
188+ } else if (!empty ($ class ['package ' ]['fullPackage ' ])) {
189+ $ namespace = '@ ' . $ class ['package ' ]['fullPackage ' ] . ':: ' ;
167190 } else {
168191 $ namespace = '' ;
169192 }
170193
171- $ output .= PHP_EOL . $ namespace . ':: ' . $ className
172- . PHP_EOL . ' Methods: ' . $ coveredMethods . '/ ' . count ($ class ['methods ' ])
173- . ' Lines: ' . $ classStatements . '/ ' . $ coveredClassStatements ;
194+ if ($ coveredClassStatements != 0 || $ this ->showUncoveredFiles || true ) {
195+ $ output .= PHP_EOL . $ namespace . $ className
196+ . PHP_EOL . ' Methods: ' . $ coveredMethods . '/ ' . count ($ class ['methods ' ])
197+ . ' Lines: ' . $ classStatements . '/ ' . $ coveredClassStatements ;
198+ }
174199
175200 }
176201 }
177202 $ this ->outputStream ->write ($ output );
178203 return ;
179204
180205 }
206+
207+ protected function getCoverageColor ($ numberOfCoveredElements , $ totalNumberOfElements ) {
208+ if ($ totalNumberOfElements > 0 ) {
209+ $ coverage = $ numberOfCoveredElements / $ totalNumberOfElements ;
210+ }
211+ return $ this ->colors ['red ' ];
212+ }
213+
181214}
0 commit comments