1: <?php
2: /**
3: * Generates code coverage reports in Simple plain text from data obtained from PHPUnit
4: *
5: * PHP5
6: *
7: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8: * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
9: *
10: * Licensed under The MIT License
11: * Redistributions of files must retain the above copyright notice.
12: *
13: * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
14: * @link http://cakephp.org CakePHP(tm) Project
15: * @package Cake.TestSuite.Coverage
16: * @since CakePHP(tm) v 2.0
17: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
18: */
19:
20: App::uses('BaseCoverageReport', 'TestSuite/Coverage');
21:
22: /**
23: * Generates code coverage reports in Simple plain text from data obtained from PHPUnit
24: *
25: * @package Cake.TestSuite.Coverage
26: */
27: class TextCoverageReport extends BaseCoverageReport {
28:
29: /**
30: * Generates report text to display.
31: *
32: * @return string compiled plain text report.
33: */
34: public function report() {
35: $pathFilter = $this->getPathFilter();
36: $coverageData = $this->filterCoverageDataByPath($pathFilter);
37: if (empty($coverageData)) {
38: return 'No files to generate coverage for';
39: }
40: $output = "\nCoverage Report:\n\n";
41: foreach ($coverageData as $file => $coverageData) {
42: $fileData = file($file);
43: $output .= $this->generateDiff($file, $fileData, $coverageData);
44: }
45: return $output;
46: }
47:
48: /**
49: * Generates a 'diff' report for a file.
50: * Since diffs are too big for plain text reports a simple file => % covered is done.
51: *
52: * @param string $filename Name of the file having coverage generated
53: * @param array $fileLines File data as an array. See file() for how to get one of these.
54: * @param array $coverageData Array of coverage data to use to generate HTML diffs with
55: * @return string
56: */
57: public function generateDiff($filename, $fileLines, $coverageData) {
58: list($covered, $total) = $this->_calculateCoveredLines($fileLines, $coverageData);
59: $percentCovered = round(100 * $covered / $total, 2);
60: return "$filename : $percentCovered%\n";
61: }
62:
63: }
64: