From d349551dd76dfd788ae0e1ed1902fd10aa8f666d Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 12 May 2010 22:43:44 -0400 Subject: [PATCH] Adding tests for generating method coverage with the reporter. Adding method visibility --- .../cases/libs/html_coverage_report.test.php | 68 +++++++++++++++++++ .../lib/coverage/html_coverage_report.php | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/html_coverage_report.test.php b/cake/tests/cases/libs/html_coverage_report.test.php index 68a5d9262..227205816 100644 --- a/cake/tests/cases/libs/html_coverage_report.test.php +++ b/cake/tests/cases/libs/html_coverage_report.test.php @@ -189,6 +189,74 @@ class HtmlCoverageReportTest extends CakeTestCase { } } +/** + * test that covering methods show up as title attributes for lines. + * + * @return void + */ + function testCoveredLinesTitleAttributes() { + $file = array( + 'line 1', + 'line 2', + 'line 3', + 'line 4', + 'line 5', + ); + $mock = $this->getMock('PHPUnit_Framework_TestCase'); + $mock->expects($this->any())->method('getName')->will($this->returnValue('testAwesomeness')); + + $rawdata = array( + array( + 'test' => $mock, + 'files' => array( + 'myfile.php' => array( + 1 => 1, + 3 => 1, + 4 => 1, + ) + ), + 'executable' => array( + 'myfile.php' => array( + 5 => -1 + ) + ) + ) + ); + + $coverage = array( + 'covered' => array( + 1 => 1, + 3 => 1, + 4 => 1, + ), + 'executable' => array( + 5 => -1, + ), + 'dead' => array( + 2 => -2 + ) + ); + $this->Coverage->setCoverage($rawdata); + $result = $this->Coverage->generateDiff('myfile.php', $file, $coverage); + + $this->assertTrue( + strpos($result, "title=\"Covered by:\ntestAwesomeness\n\">1") !== false, + 'Missing method coverage for line 1' + ); + $this->assertTrue( + strpos($result, "title=\"Covered by:\ntestAwesomeness\n\">3") !== false, + 'Missing method coverage for line 3' + ); + $this->assertTrue( + strpos($result, "title=\"Covered by:\ntestAwesomeness\n\">4") !== false, + 'Missing method coverage for line 4' + ); + $this->assertTrue( + strpos($result, "title=\"\">5") !== false, + 'Coverage report is wrong for line 5' + ); + } + /** * teardown * diff --git a/cake/tests/lib/coverage/html_coverage_report.php b/cake/tests/lib/coverage/html_coverage_report.php index 1e581f787..4d778e03e 100644 --- a/cake/tests/lib/coverage/html_coverage_report.php +++ b/cake/tests/lib/coverage/html_coverage_report.php @@ -178,7 +178,7 @@ HTML; * @param array $coverageData Array of coverage data to use to generate HTML diffs with * @return string HTML diff. */ - function generateDiff($filename, $fileLines, $coverageData) { + public function generateDiff($filename, $fileLines, $coverageData) { $output = ''; $diff = array(); $covered = 0;