initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,127 @@
<?php
/**
* $Id: CoverageMerger.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/system/util/Properties.php';
/**
* Saves coverage output of the test to a specified database
*
* @author Michiel Rook <michiel.rook@gmail.com>
* @version $Id: CoverageMerger.php 3076 2006-12-18 08:52:12Z fabien $
* @package phing.tasks.ext.coverage
* @since 2.1.0
*/
class CoverageMerger
{
private static function mergeCodeCoverage($left, $right)
{
$coverageMerged = array();
reset($left);
reset($right);
while (current($left) && current($right))
{
$linenr_left = key($left);
$linenr_right = key($right);
if ($linenr_left < $linenr_right)
{
$coverageMerged[$linenr_left] = current($left);
next($left);
}
else
if ($linenr_right < $linenr_left)
{
$coverageMerged[$linenr_right] = current($right);
next($right);
}
else
{
if (current($left) < 0)
{
$coverageMerged[$linenr_right] = current($right);
}
else
if (current($right) < 0)
{
$coverageMerged[$linenr_right] = current($left);
}
else
{
$coverageMerged[$linenr_right] = current($left) + current($right);
}
next($left);
next($right);
}
}
while (current($left))
{
$coverageMerged[key($left)] = current($left);
next($left);
}
while (current($right))
{
$coverageMerged[key($right)] = current($right);
next($right);
}
return $coverageMerged;
}
static function merge($project, $codeCoverageInformation)
{
$database = new PhingFile($project->getProperty('coverage.database'));
$props = new Properties();
$props->load($database);
$coverageTotal = $codeCoverageInformation;
foreach ($coverageTotal as $coverage)
{
foreach ($coverage as $filename => $coverageFile)
{
$filename = strtolower($filename);
if ($props->getProperty($filename) != null)
{
$file = unserialize($props->getProperty($filename));
$left = $file['coverage'];
$right = $coverageFile;
$coverageMerged = CoverageMerger::mergeCodeCoverage($left, $right);
$file['coverage'] = $coverageMerged;
$props->setProperty($filename, serialize($file));
}
}
}
$props->store($database);
}
}
?>

View File

@ -0,0 +1,92 @@
<?php
/**
* $Id: CoverageMergerTask.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
require_once 'phing/system/io/PhingFile.php';
require_once 'phing/system/io/Writer.php';
require_once 'phing/system/util/Properties.php';
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
/**
* Merges code coverage snippets into a code coverage database
*
* @author Michiel Rook <michiel.rook@gmail.com>
* @version $Id: CoverageMergerTask.php 3076 2006-12-18 08:52:12Z fabien $
* @package phing.tasks.ext.coverage
* @since 2.1.0
*/
class CoverageMergerTask extends Task
{
/** the list of filesets containing the .php filename rules */
private $filesets = array();
/**
* Add a new fileset containing the .php files to process
*
* @param FileSet the new fileset containing .php files
*/
function addFileSet(FileSet $fileset)
{
$this->filesets[] = $fileset;
}
/**
* Iterate over all filesets and return all the filenames.
*
* @return array an array of filenames
*/
private function getFilenames()
{
$files = array();
foreach ($this->filesets as $fileset)
{
$ds = $fileset->getDirectoryScanner($this->project);
$ds->scan();
$includedFiles = $ds->getIncludedFiles();
foreach ($includedFiles as $file)
{
$fs = new PhingFile(basename($ds->getBaseDir()), $file);
$files[] = $fs->getAbsolutePath();
}
}
return $files;
}
function main()
{
$files = $this->getFilenames();
$this->log("Merging " . count($files) . " coverage files");
foreach ($files as $file)
{
$coverageInformation = unserialize(file_get_contents($file));
CoverageMerger::merge($this->project, array($coverageInformation));
}
}
}
?>

View File

@ -0,0 +1,407 @@
<?php
/**
* $Id: CoverageReportTask.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
require_once 'phing/system/io/PhingFile.php';
require_once 'phing/system/io/Writer.php';
require_once 'phing/system/util/Properties.php';
require_once 'phing/tasks/ext/phpunit2/PHPUnit2Util.php';
require_once 'phing/tasks/ext/coverage/CoverageReportTransformer.php';
/**
* Transforms information in a code coverage database to XML
*
* @author Michiel Rook <michiel.rook@gmail.com>
* @version $Id: CoverageReportTask.php 3076 2006-12-18 08:52:12Z fabien $
* @package phing.tasks.ext.coverage
* @since 2.1.0
*/
class CoverageReportTask extends Task
{
private $outfile = "coverage.xml";
private $transformers = array();
/** the classpath to use (optional) */
private $classpath = NULL;
/** the path to the GeSHi library (optional) */
private $geshipath = "";
/** the path to the GeSHi language files (optional) */
private $geshilanguagespath = "";
function setClasspath(Path $classpath)
{
if ($this->classpath === null)
{
$this->classpath = $classpath;
}
else
{
$this->classpath->append($classpath);
}
}
function createClasspath()
{
$this->classpath = new Path();
return $this->classpath;
}
function setGeshiPath($path)
{
$this->geshipath = $path;
}
function setGeshiLanguagesPath($path)
{
$this->geshilanguagespath = $path;
}
function __construct()
{
$this->doc = new DOMDocument();
$this->doc->encoding = 'UTF-8';
$this->doc->formatOutput = true;
$this->doc->appendChild($this->doc->createElement('snapshot'));
}
function setOutfile($outfile)
{
$this->outfile = $outfile;
}
/**
* Generate a report based on the XML created by this task
*/
function createReport()
{
$transformer = new CoverageReportTransformer($this);
$this->transformers[] = $transformer;
return $transformer;
}
protected function getPackageElement($packageName)
{
$packages = $this->doc->documentElement->getElementsByTagName('package');
foreach ($packages as $package)
{
if ($package->getAttribute('name') == $packageName)
{
return $package;
}
}
return NULL;
}
protected function addClassToPackage($classname, $element)
{
$packageName = PHPUnit2Util::getPackageName($classname);
$package = $this->getPackageElement($packageName);
if ($package === NULL)
{
$package = $this->doc->createElement('package');
$package->setAttribute('name', $packageName);
$this->doc->documentElement->appendChild($package);
}
$package->appendChild($element);
}
protected function stripDiv($source)
{
$openpos = strpos($source, "<div");
$closepos = strpos($source, ">", $openpos);
$line = substr($source, $closepos + 1);
$tagclosepos = strpos($line, "</div>");
$line = substr($line, 0, $tagclosepos);
return $line;
}
protected function highlightSourceFile($filename)
{
if ($this->geshipath)
{
require_once $this->geshipath . '/geshi.php';
$source = file_get_contents($filename);
$geshi = new GeSHi($source, 'php', $this->geshilanguagespath);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->enable_strict_mode(true);
$geshi->enable_classes(true);
$geshi->set_url_for_keyword_group(3, '');
$html = $geshi->parse_code();
$lines = split("<li>|</li>", $html);
// skip first and last line
array_pop($lines);
array_shift($lines);
$lines = array_filter($lines);
$lines = array_map(array($this, 'stripDiv'), $lines);
return $lines;
}
else
{
$lines = file($filename);
for ($i = 0; $i < count($lines); $i++)
{
$line = $lines[$i];
$line = rtrim($line);
$lines[$i] = utf8_encode($line);
}
return $lines;
}
}
protected function transformSourceFile($filename, $coverageInformation, $classStartLine = 1)
{
$sourceElement = $this->doc->createElement('sourcefile');
$sourceElement->setAttribute('name', basename($filename));
$filelines = $this->highlightSourceFile($filename);
$linenr = 1;
foreach ($filelines as $line)
{
$lineElement = $this->doc->createElement('sourceline');
$lineElement->setAttribute('coveredcount', (isset($coverageInformation[$linenr]) ? $coverageInformation[$linenr] : '0'));
if ($linenr == $classStartLine)
{
$lineElement->setAttribute('startclass', 1);
}
$textnode = $this->doc->createTextNode($line);
$lineElement->appendChild($textnode);
$sourceElement->appendChild($lineElement);
$linenr++;
}
return $sourceElement;
}
protected function filterCovered($var)
{
return ($var >= 0);
}
protected function transformCoverageInformation($filename, $coverageInformation)
{
// Strip last line of coverage information
end($coverageInformation);
unset($coverageInformation[key($coverageInformation)]);
$classes = PHPUnit2Util::getDefinedClasses($filename, $this->classpath);
if (is_array($classes))
{
foreach ($classes as $classname)
{
$reflection = new ReflectionClass($classname);
$methods = $reflection->getMethods();
$classElement = $this->doc->createElement('class');
$classElement->setAttribute('name', $reflection->getName());
$this->addClassToPackage($reflection->getName(), $classElement);
$classStartLine = $reflection->getStartLine();
$methodscovered = 0;
$methodcount = 0;
// Strange PHP5 reflection bug, classes without parent class or implemented interfaces seem to start one line off
if ($reflection->getParentClass() == NULL && count($reflection->getInterfaces()) == 0)
{
unset($coverageInformation[$classStartLine + 1]);
}
else
{
unset($coverageInformation[$classStartLine]);
}
reset($coverageInformation);
foreach ($methods as $method)
{
// PHP5 reflection considers methods of a parent class to be part of a subclass, we don't
if ($method->getDeclaringClass()->getName() != $reflection->getName())
{
continue;
}
// small fix for XDEBUG_CC_UNUSED
if (isset($coverageInformation[$method->getStartLine()]))
{
unset($coverageInformation[$method->getStartLine()]);
}
if (isset($coverageInformation[$method->getEndLine()]))
{
unset($coverageInformation[$method->getEndLine()]);
}
if ($method->isAbstract())
{
continue;
}
$linenr = key($coverageInformation);
while ($linenr !== null && $linenr < $method->getStartLine())
{
next($coverageInformation);
$linenr = key($coverageInformation);
}
if (current($coverageInformation) > 0 && $method->getStartLine() <= $linenr && $linenr <= $method->getEndLine())
{
$methodscovered++;
}
$methodcount++;
}
$statementcount = count($coverageInformation);
$statementscovered = count(array_filter($coverageInformation, array($this, 'filterCovered')));
$classElement->appendChild($this->transformSourceFile($filename, $coverageInformation, $classStartLine));
$classElement->setAttribute('methodcount', $methodcount);
$classElement->setAttribute('methodscovered', $methodscovered);
$classElement->setAttribute('statementcount', $statementcount);
$classElement->setAttribute('statementscovered', $statementscovered);
$classElement->setAttribute('totalcount', $methodcount + $statementcount);
$classElement->setAttribute('totalcovered', $methodscovered + $statementscovered);
}
}
}
protected function calculateStatistics()
{
$packages = $this->doc->documentElement->getElementsByTagName('package');
$totalmethodcount = 0;
$totalmethodscovered = 0;
$totalstatementcount = 0;
$totalstatementscovered = 0;
foreach ($packages as $package)
{
$methodcount = 0;
$methodscovered = 0;
$statementcount = 0;
$statementscovered = 0;
$classes = $package->getElementsByTagName('class');
foreach ($classes as $class)
{
$methodcount += $class->getAttribute('methodcount');
$methodscovered += $class->getAttribute('methodscovered');
$statementcount += $class->getAttribute('statementcount');
$statementscovered += $class->getAttribute('statementscovered');
}
$package->setAttribute('methodcount', $methodcount);
$package->setAttribute('methodscovered', $methodscovered);
$package->setAttribute('statementcount', $statementcount);
$package->setAttribute('statementscovered', $statementscovered);
$package->setAttribute('totalcount', $methodcount + $statementcount);
$package->setAttribute('totalcovered', $methodscovered + $statementscovered);
$totalmethodcount += $methodcount;
$totalmethodscovered += $methodscovered;
$totalstatementcount += $statementcount;
$totalstatementscovered += $statementscovered;
}
$this->doc->documentElement->setAttribute('methodcount', $totalmethodcount);
$this->doc->documentElement->setAttribute('methodscovered', $totalmethodscovered);
$this->doc->documentElement->setAttribute('statementcount', $totalstatementcount);
$this->doc->documentElement->setAttribute('statementscovered', $totalstatementscovered);
$this->doc->documentElement->setAttribute('totalcount', $totalmethodcount + $totalstatementcount);
$this->doc->documentElement->setAttribute('totalcovered', $totalmethodscovered + $totalstatementscovered);
}
function main()
{
$this->log("Transforming coverage report");
$database = new PhingFile($this->project->getProperty('coverage.database'));
$props = new Properties();
$props->load($database);
foreach ($props->keys() as $filename)
{
$file = unserialize($props->getProperty($filename));
$this->transformCoverageInformation($file['fullname'], $file['coverage']);
}
$this->calculateStatistics();
$this->doc->save($this->outfile);
foreach ($this->transformers as $transformer)
{
$transformer->setXmlDocument($this->doc);
$transformer->transform();
}
}
}
?>

View File

@ -0,0 +1,121 @@
<?php
/**
* $Id: CoverageReportTransformer.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
require_once 'phing/system/io/PhingFile.php';
require_once 'phing/system/io/FileWriter.php';
require_once 'phing/util/ExtendedFileStream.php';
/**
* Transform a Phing/Xdebug code coverage xml report.
* The default transformation generates an html report in framed style.
*
* @author Michiel Rook <michiel.rook@gmail.com>
* @version $Id: CoverageReportTransformer.php 3076 2006-12-18 08:52:12Z fabien $
* @package phing.tasks.ext.coverage
* @since 2.1.0
*/
class CoverageReportTransformer
{
private $task = NULL;
private $styleDir = "";
private $toDir = "";
private $document = NULL;
function __construct(Task $task)
{
$this->task = $task;
}
function setStyleDir($styleDir)
{
$this->styleDir = $styleDir;
}
function setToDir($toDir)
{
$this->toDir = $toDir;
}
function setXmlDocument($document)
{
$this->document = $document;
}
function transform()
{
$dir = new PhingFile($this->toDir);
if (!$dir->exists())
{
throw new BuildException("Directory '" . $this->toDir . "' does not exist");
}
$xslfile = $this->getStyleSheet();
$xsl = new DOMDocument();
$xsl->load($xslfile->getAbsolutePath());
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
ExtendedFileStream::registerStream();
// no output for the framed report
// it's all done by extension...
$proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
$proc->transformToXML($this->document);
}
private function getStyleSheet()
{
$xslname = "coverage-frames.xsl";
if ($this->styleDir)
{
$file = new PhingFile($this->styleDir, $xslname);
}
else
{
$path = Phing::getResourcePath("phing/etc/$xslname");
if ($path === NULL)
{
$path = Phing::getResourcePath("etc/$xslname");
if ($path === NULL)
{
throw new BuildException("Could not find $xslname in resource path");
}
}
$file = new PhingFile($path);
}
if (!$file->exists())
{
throw new BuildException("Could not find file " . $file->getPath());
}
return $file;
}
}
?>

View File

@ -0,0 +1,163 @@
<?php
/**
* $Id: CoverageSetupTask.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
require_once 'phing/system/io/PhingFile.php';
require_once 'phing/system/io/Writer.php';
require_once 'phing/system/util/Properties.php';
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
/**
* Initializes a code coverage database
*
* @author Michiel Rook <michiel.rook@gmail.com>
* @version $Id: CoverageSetupTask.php 3076 2006-12-18 08:52:12Z fabien $
* @package phing.tasks.ext.coverage
* @since 2.1.0
*/
class CoverageSetupTask extends Task
{
/** the list of filesets containing the .php filename rules */
private $filesets = array();
/** the filename of the coverage database */
private $database = "coverage.db";
/** the classpath to use (optional) */
private $classpath = NULL;
/**
* Add a new fileset containing the .php files to process
*
* @param FileSet the new fileset containing .php files
*/
function addFileSet(FileSet $fileset)
{
$this->filesets[] = $fileset;
}
/**
* Sets the filename of the coverage database to use
*
* @param string the filename of the database
*/
function setDatabase($database)
{
$this->database = $database;
}
function setClasspath(Path $classpath)
{
if ($this->classpath === null)
{
$this->classpath = $classpath;
}
else
{
$this->classpath->append($classpath);
}
}
function createClasspath()
{
$this->classpath = new Path();
return $this->classpath;
}
/**
* Iterate over all filesets and return the filename of all files
* that end with .php. This is to avoid loading an xml file
* for example.
*
* @return array an array of (basedir, filenames) pairs
*/
private function getFilenames()
{
$files = array();
foreach ($this->filesets as $fileset)
{
$ds = $fileset->getDirectoryScanner($this->project);
$ds->scan();
$includedFiles = $ds->getIncludedFiles();
foreach ($includedFiles as $file)
{
if (strstr($file, ".php"))
{
$fs = new PhingFile(realpath($ds->getBaseDir()), $file);
$files[] = array('key' => strtolower($fs->getAbsolutePath()), 'fullname' => $fs->getAbsolutePath());
}
}
}
return $files;
}
function init()
{
include_once 'PHPUnit2/Framework/TestCase.php';
if (!class_exists('PHPUnit2_Framework_TestCase')) {
throw new Exception("PHPUnit2Task depends on PEAR PHPUnit2 package being installed.");
}
}
function main()
{
$files = $this->getFilenames();
$this->log("Setting up coverage database for " . count($files) . " files");
$props = new Properties();
foreach ($files as $file)
{
$fullname = $file['fullname'];
$filename = $file['key'];
$props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
}
$dbfile = new PhingFile($this->database);
$props->store($dbfile);
$this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
foreach ($files as $file)
{
$fullname = $file['fullname'];
xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
Phing::__import($fullname, $this->classpath);
$coverage = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
CoverageMerger::merge($this->project, array($coverage));
}
}
}
?>