Skip to content

Commit

Permalink
Adding tests for generating method coverage with the reporter.
Browse files Browse the repository at this point in the history
Adding method visibility
  • Loading branch information
markstory committed May 13, 2010
1 parent cb9d6f4 commit d349551
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
68 changes: 68 additions & 0 deletions cake/tests/cases/libs/html_coverage_report.test.php
Expand Up @@ -189,6 +189,74 @@ function testGenerateDiff() {
}
}

/**
* 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\"><span class=\"line-num\">1") !== false,
'Missing method coverage for line 1'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">3") !== false,
'Missing method coverage for line 3'
);
$this->assertTrue(
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">4") !== false,
'Missing method coverage for line 4'
);
$this->assertTrue(
strpos($result, "title=\"\"><span class=\"line-num\">5") !== false,
'Coverage report is wrong for line 5'
);
}

/**
* teardown
*
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/lib/coverage/html_coverage_report.php
Expand Up @@ -178,7 +178,7 @@ public function filterCoverageDataByPath($path) {
* @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;
Expand Down

0 comments on commit d349551

Please sign in to comment.