示例#1
0
文件: View.php 项目: peopleplan/Pyrus
 function renderSummary(Aggregator $agg, array $results, $istest = false, $total = 1, $covered = 1, $dead = 1)
 {
     $output = new \XMLWriter();
     if (!$output->openUri('php://output')) {
         throw new Exception('Cannot render test summary, opening XML failed');
     }
     $output->setIndentString(' ');
     $output->setIndent(true);
     $output->startElement('html');
     $output->startElement('head');
     if ($istest) {
         $output->writeElement('title', 'Code Coverage Summary [' . $istest . ']');
     } else {
         $output->writeElement('title', 'Code Coverage Summary');
     }
     $output->startElement('link');
     $output->writeAttribute('href', 'cover.css');
     $output->writeAttribute('rel', 'stylesheet');
     $output->writeAttribute('type', 'text/css');
     $output->endElement();
     $output->endElement();
     $output->startElement('body');
     if ($istest) {
         $output->writeElement('h2', 'Code Coverage Files for test ' . $istest);
     } else {
         $output->writeElement('h2', 'Code Coverage Files');
         $output->writeElement('h3', 'Total lines: ' . $total . ', covered lines: ' . $covered . ', dead lines: ' . $dead);
         $percent = 0;
         if ($total > 0) {
             $percent = round($covered / $total * 100, 1);
         }
         $output->startElement('p');
         if ($percent < 50) {
             $output->writeAttribute('class', 'bad');
         } elseif ($percent < 75) {
             $output->writeAttribute('class', 'ok');
         } else {
             $output->writeAttribute('class', 'good');
         }
         $output->text($percent . '% code coverage');
         $output->endElement();
     }
     $this->logoutLink($output);
     $output->startElement('p');
     $output->startElement('a');
     $output->writeAttribute('href', $this->controller->getTOCLink(true));
     $output->text('Code Coverage per PHPT test');
     $output->endElement();
     $output->endElement();
     $output->startElement('ul');
     foreach ($results as $i => $name) {
         $output->flush();
         $source = new SourceFile($name, $agg, $agg->testpath, $agg->codepath, null, false);
         $output->startElement('li');
         $percent = $source->coveragePercentage();
         $output->startElement('div');
         if ($percent < 50) {
             $output->writeAttribute('class', 'bad');
         } elseif ($percent < 75) {
             $output->writeAttribute('class', 'ok');
         } else {
             $output->writeAttribute('class', 'good');
         }
         $output->text(' Coverage: ' . str_pad($percent . '%', 4, ' ', STR_PAD_LEFT));
         $output->endElement();
         $output->startElement('a');
         $output->writeAttribute('href', $this->mangleFile($name, $istest));
         $output->text($source->shortName());
         $output->endElement();
         $output->endElement();
     }
     $output->endElement();
     $output->endElement();
     $output->endDocument();
 }
示例#2
0
 function __construct($path, Aggregator $agg, $testpath, $sourcepath, $testname)
 {
     $this->testname = $testname;
     parent::__construct($path, $agg, $testpath, $sourcepath);
 }