Adding tests for generating method coverage with the reporter.

Adding method visibility
This commit is contained in:
Mark Story 2010-05-12 22:43:44 -04:00
parent cb9d6f478d
commit d349551dd7
2 changed files with 69 additions and 1 deletions

View file

@ -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\"><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
*

View file

@ -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;