CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.
This commit is contained in:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
207
airtime_mvc/library/phing/tasks/ext/phpunit/BatchTest.php
Normal file
207
airtime_mvc/library/phing/tasks/ext/phpunit/BatchTest.php
Normal file
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: BatchTest.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/types/FileSet.php';
|
||||
|
||||
/**
|
||||
* Scans a list of files given by the fileset attribute, extracts valid test cases
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: BatchTest.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class BatchTest
|
||||
{
|
||||
/** the list of filesets containing the testcase filename rules */
|
||||
private $filesets = array();
|
||||
|
||||
/** the reference to the project */
|
||||
private $project = NULL;
|
||||
|
||||
/** the classpath to use with Phing::__import() calls */
|
||||
private $classpath = NULL;
|
||||
|
||||
/** names of classes to exclude */
|
||||
private $excludeClasses = array();
|
||||
|
||||
/** name of the batchtest/suite */
|
||||
protected $name = "Phing Batchtest";
|
||||
|
||||
/**
|
||||
* Create a new batchtest instance
|
||||
*
|
||||
* @param Project the project it depends on.
|
||||
*/
|
||||
public function __construct(Project $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the batchtest/suite
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the classes to exclude
|
||||
*/
|
||||
public function setExclude($exclude)
|
||||
{
|
||||
$this->excludeClasses = explode(" ", $exclude);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the classpath
|
||||
*/
|
||||
public function setClasspath(Path $classpath)
|
||||
{
|
||||
if ($this->classpath === null)
|
||||
{
|
||||
$this->classpath = $classpath;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->classpath->append($classpath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Path object
|
||||
*/
|
||||
public function createClasspath()
|
||||
{
|
||||
$this->classpath = new Path();
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the classpath
|
||||
*/
|
||||
public function getClasspath()
|
||||
{
|
||||
return $this->classpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fileset containing the XML results to aggregate
|
||||
*
|
||||
* @param FileSet the new fileset containing XML results.
|
||||
*/
|
||||
public function addFileSet(FileSet $fileset)
|
||||
{
|
||||
$this->filesets[] = $fileset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over all filesets and return the filename of all files.
|
||||
*
|
||||
* @return array an array of filenames
|
||||
*/
|
||||
private function getFilenames()
|
||||
{
|
||||
$filenames = array();
|
||||
|
||||
foreach ($this->filesets as $fileset)
|
||||
{
|
||||
$ds = $fileset->getDirectoryScanner($this->project);
|
||||
$ds->scan();
|
||||
|
||||
$files = $ds->getIncludedFiles();
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filenames[] = $ds->getBaseDir() . "/" . $file;
|
||||
}
|
||||
}
|
||||
|
||||
return $filenames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks wheter $input is a PHPUnit Test
|
||||
*/
|
||||
private function isTestCase($input)
|
||||
{
|
||||
return is_subclass_of($input, 'PHPUnit_Framework_TestCase') || is_subclass_of($input, 'PHPUnit_Framework_TestSuite');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an array of classes, removes all classes that are not test cases or test suites,
|
||||
* or classes that are declared abstract
|
||||
*/
|
||||
private function filterTests($input)
|
||||
{
|
||||
$reflect = new ReflectionClass($input);
|
||||
|
||||
return $this->isTestCase($input) && (!$reflect->isAbstract());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of test cases and test suites that are declared
|
||||
* by the files included by the filesets
|
||||
*
|
||||
* @return array an array of tests.
|
||||
*/
|
||||
protected function elements()
|
||||
{
|
||||
$filenames = $this->getFilenames();
|
||||
|
||||
$declaredClasses = array();
|
||||
|
||||
foreach ($filenames as $filename)
|
||||
{
|
||||
$definedClasses = PHPUnitUtil::getDefinedClasses($filename, $this->classpath);
|
||||
|
||||
foreach($definedClasses as $definedClass) {
|
||||
$this->project->log("(PHPUnit) Adding $definedClass (from $filename) to tests.", Project::MSG_DEBUG);
|
||||
}
|
||||
|
||||
$declaredClasses = array_merge($declaredClasses, $definedClasses);
|
||||
}
|
||||
|
||||
$elements = array_filter($declaredClasses, array($this, "filterTests"));
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a testsuite containing all the tests in this batch
|
||||
*
|
||||
* @return PHPUnit_Framework_TestSuite
|
||||
*/
|
||||
public function getTestSuite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite($this->name);
|
||||
|
||||
foreach ($this->elements() as $test)
|
||||
{
|
||||
$testClass = new ReflectionClass($test);
|
||||
|
||||
$suite->addTestSuite($testClass);
|
||||
}
|
||||
|
||||
return $suite;
|
||||
}
|
||||
}
|
178
airtime_mvc/library/phing/tasks/ext/phpunit/FormatterElement.php
Normal file
178
airtime_mvc/library/phing/tasks/ext/phpunit/FormatterElement.php
Normal file
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: FormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/io/PhingFile.php';
|
||||
|
||||
/**
|
||||
* A wrapper for the implementations of PHPUnit2ResultFormatter.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: FormatterElement.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class FormatterElement
|
||||
{
|
||||
protected $formatter = NULL;
|
||||
|
||||
protected $type = "";
|
||||
|
||||
protected $useFile = true;
|
||||
|
||||
protected $toDir = ".";
|
||||
|
||||
protected $outfile = "";
|
||||
|
||||
protected $parent = NULL;
|
||||
|
||||
/**
|
||||
* Sets parent task
|
||||
* @param Task $parent Calling Task
|
||||
*/
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific formatter type
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
if ($this->type == "summary")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/SummaryPHPUnitResultFormatter.php';
|
||||
$this->formatter = new SummaryPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
if ($this->type == "clover")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/CloverPHPUnitResultFormatter.php';
|
||||
$this->formatter = new CloverPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
if ($this->type == "xml")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/XMLPHPUnitResultFormatter.php';
|
||||
$this->formatter = new XMLPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
if ($this->type == "plain")
|
||||
{
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/PlainPHPUnitResultFormatter.php';
|
||||
$this->formatter = new PlainPHPUnitResultFormatter($this->parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BuildException("Formatter '" . $this->type . "' not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific formatter class
|
||||
*/
|
||||
public function setClassName($className)
|
||||
{
|
||||
$classNameNoDot = Phing::import($className);
|
||||
|
||||
$this->formatter = new $classNameNoDot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to store formatting results in a file
|
||||
*/
|
||||
public function setUseFile($useFile)
|
||||
{
|
||||
$this->useFile = $useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to store formatting results in a file
|
||||
*/
|
||||
public function getUseFile()
|
||||
{
|
||||
return $this->useFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets output directory
|
||||
* @param string $toDir
|
||||
*/
|
||||
public function setToDir($toDir)
|
||||
{
|
||||
$this->toDir = $toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns output directory
|
||||
* @return string
|
||||
*/
|
||||
public function getToDir()
|
||||
{
|
||||
return $this->toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets output filename
|
||||
* @param string $outfile
|
||||
*/
|
||||
public function setOutfile($outfile)
|
||||
{
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns output filename
|
||||
* @return string
|
||||
*/
|
||||
public function getOutfile()
|
||||
{
|
||||
if ($this->outfile)
|
||||
{
|
||||
return $this->outfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->formatter->getPreferredOutfile() . $this->getExtension();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extension
|
||||
* @return string
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
return $this->formatter->getExtension();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatter object
|
||||
* @return PHPUnitResultFormatter
|
||||
*/
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitReportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 PHPUnit xml report using XSLT.
|
||||
* This transformation generates an html report in either framed or non-framed
|
||||
* style. The non-framed style is convenient to have a concise report via mail,
|
||||
* the framed report is much more convenient if you want to browse into
|
||||
* different packages or testcases since it is a Javadoc like report.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitReportTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitReportTask extends Task
|
||||
{
|
||||
private $format = "noframes";
|
||||
private $styleDir = "";
|
||||
private $toDir = "";
|
||||
|
||||
/** the directory where the results XML can be found */
|
||||
private $inFile = "testsuites.xml";
|
||||
|
||||
/**
|
||||
* Set the filename of the XML results file to use.
|
||||
*/
|
||||
public function setInFile($inFile)
|
||||
{
|
||||
$this->inFile = $inFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of the generated report. Must be noframes or frames.
|
||||
*/
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory where the stylesheets are located.
|
||||
*/
|
||||
public function setStyleDir($styleDir)
|
||||
{
|
||||
$this->styleDir = $styleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory where the files resulting from the
|
||||
* transformation should be written to.
|
||||
*/
|
||||
public function setToDir($toDir)
|
||||
{
|
||||
$this->toDir = $toDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the XSL stylesheet
|
||||
*/
|
||||
protected function getStyleSheet()
|
||||
{
|
||||
$xslname = "phpunit-" . $this->format . ".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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the DOM document
|
||||
*/
|
||||
protected function transform(DOMDocument $document)
|
||||
{
|
||||
$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);
|
||||
|
||||
if ($this->format == "noframes")
|
||||
{
|
||||
$writer = new FileWriter(new PhingFile($this->toDir, "phpunit-noframes.html"));
|
||||
$writer->write($proc->transformToXML($document));
|
||||
$writer->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtendedFileStream::registerStream();
|
||||
|
||||
// no output for the framed report
|
||||
// it's all done by extension...
|
||||
$dir = new PhingFile($this->toDir);
|
||||
$proc->setParameter('', 'output.dir', $dir->toString());
|
||||
$proc->transformToXML($document);
|
||||
|
||||
ExtendedFileStream::unregisterStream();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes DOM document tree:
|
||||
* - adds package="default" to 'testsuite' elements without
|
||||
* package attribute
|
||||
* - removes outer 'testsuite' container(s)
|
||||
*/
|
||||
protected function fixDocument(DOMDocument $document)
|
||||
{
|
||||
$rootElement = $document->firstChild;
|
||||
|
||||
$xp = new DOMXPath($document);
|
||||
|
||||
$nodes = $xp->query("/testsuites/testsuite");
|
||||
|
||||
foreach ($nodes as $node)
|
||||
{
|
||||
$children = $xp->query("./testsuite", $node);
|
||||
|
||||
foreach ($children as $child)
|
||||
{
|
||||
if (!$child->hasAttribute('package'))
|
||||
{
|
||||
$child->setAttribute('package', 'default');
|
||||
}
|
||||
|
||||
$rootElement->appendChild($child);
|
||||
}
|
||||
|
||||
$rootElement->removeChild($node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the task
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (!class_exists('XSLTProcessor')) {
|
||||
throw new BuildException("PHPUnitReportTask requires the XSL extension");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
$testSuitesDoc = new DOMDocument();
|
||||
$testSuitesDoc->load($this->inFile);
|
||||
|
||||
$this->fixDocument($testSuitesDoc);
|
||||
|
||||
$this->transform($testSuitesDoc);
|
||||
}
|
||||
}
|
365
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitTask.php
Normal file
365
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitTask.php
Normal file
|
@ -0,0 +1,365 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/util/LogWriter.php';
|
||||
|
||||
/**
|
||||
* Runs PHPUnit tests.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitTask.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @see BatchTest
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitTask extends Task
|
||||
{
|
||||
private $batchtests = array();
|
||||
private $formatters = array();
|
||||
private $bootstrap = "";
|
||||
private $haltonerror = false;
|
||||
private $haltonfailure = false;
|
||||
private $haltonincomplete = false;
|
||||
private $haltonskipped = false;
|
||||
private $errorproperty;
|
||||
private $failureproperty;
|
||||
private $incompleteproperty;
|
||||
private $skippedproperty;
|
||||
private $printsummary = false;
|
||||
private $testfailed = false;
|
||||
private $testfailuremessage = "";
|
||||
private $codecoverage = false;
|
||||
private $groups = array();
|
||||
private $excludeGroups = array();
|
||||
private $usecustomerrorhandler = true;
|
||||
|
||||
/**
|
||||
* Initialize Task.
|
||||
* This method includes any necessary PHPUnit2 libraries and triggers
|
||||
* appropriate error if they cannot be found. This is not done in header
|
||||
* because we may want this class to be loaded w/o triggering an error.
|
||||
*/
|
||||
public function init() {
|
||||
if (version_compare(PHP_VERSION, '5.0.3') < 0)
|
||||
{
|
||||
throw new BuildException("PHPUnitTask requires PHP version >= 5.0.3", $this->getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine PHPUnit version number
|
||||
*/
|
||||
@include_once 'PHPUnit/Runner/Version.php';
|
||||
|
||||
$version = PHPUnit_Runner_Version::id();
|
||||
|
||||
if (version_compare($version, '3.2.0') < 0)
|
||||
{
|
||||
throw new BuildException("PHPUnitTask requires PHPUnit version >= 3.2.0", $this->getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Other dependencies that should only be loaded when class is actually used.
|
||||
*/
|
||||
require_once 'phing/tasks/ext/phpunit/PHPUnitTestRunner.php';
|
||||
require_once 'phing/tasks/ext/phpunit/BatchTest.php';
|
||||
require_once 'phing/tasks/ext/phpunit/FormatterElement.php';
|
||||
|
||||
/**
|
||||
* Add some defaults to the PHPUnit filter
|
||||
*/
|
||||
$pwd = dirname(__FILE__);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/Util/Filter.php';
|
||||
|
||||
// point PHPUnit_MAIN_METHOD define to non-existing method
|
||||
if (!defined('PHPUnit_MAIN_METHOD'))
|
||||
{
|
||||
define('PHPUnit_MAIN_METHOD', 'PHPUnitTask::undefined');
|
||||
}
|
||||
|
||||
$path = realpath($pwd . '/../../../');
|
||||
if (version_compare($version, '3.5.0') >= 0) {
|
||||
PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist($path);
|
||||
} else {
|
||||
PHPUnit_Util_Filter::addDirectoryToFilter($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of a bootstrap file that is run before
|
||||
* executing the tests
|
||||
*
|
||||
* @param string $bootstrap the name of the bootstrap file
|
||||
*/
|
||||
public function setBootstrap($bootstrap)
|
||||
{
|
||||
$this->bootstrap = $bootstrap;
|
||||
}
|
||||
|
||||
public function setErrorproperty($value)
|
||||
{
|
||||
$this->errorproperty = $value;
|
||||
}
|
||||
|
||||
public function setFailureproperty($value)
|
||||
{
|
||||
$this->failureproperty = $value;
|
||||
}
|
||||
|
||||
public function setIncompleteproperty($value)
|
||||
{
|
||||
$this->incompleteproperty = $value;
|
||||
}
|
||||
|
||||
public function setSkippedproperty($value)
|
||||
{
|
||||
$this->skippedproperty = $value;
|
||||
}
|
||||
|
||||
public function setHaltonerror($value)
|
||||
{
|
||||
$this->haltonerror = $value;
|
||||
}
|
||||
|
||||
public function setHaltonfailure($value)
|
||||
{
|
||||
$this->haltonfailure = $value;
|
||||
}
|
||||
|
||||
public function getHaltonfailure()
|
||||
{
|
||||
return $this->haltonfailure;
|
||||
}
|
||||
|
||||
public function setHaltonincomplete($value)
|
||||
{
|
||||
$this->haltonincomplete = $value;
|
||||
}
|
||||
|
||||
public function getHaltonincomplete()
|
||||
{
|
||||
return $this->haltonincomplete;
|
||||
}
|
||||
|
||||
public function setHaltonskipped($value)
|
||||
{
|
||||
$this->haltonskipped = $value;
|
||||
}
|
||||
|
||||
public function getHaltonskipped()
|
||||
{
|
||||
return $this->haltonskipped;
|
||||
}
|
||||
|
||||
public function setPrintsummary($printsummary)
|
||||
{
|
||||
$this->printsummary = $printsummary;
|
||||
}
|
||||
|
||||
public function setCodecoverage($codecoverage)
|
||||
{
|
||||
$this->codecoverage = $codecoverage;
|
||||
}
|
||||
|
||||
public function setUseCustomErrorHandler($usecustomerrorhandler)
|
||||
{
|
||||
$this->usecustomerrorhandler = $usecustomerrorhandler;
|
||||
}
|
||||
|
||||
public function setGroups($groups)
|
||||
{
|
||||
$token = ' ,;';
|
||||
$this->groups = array();
|
||||
$tok = strtok($groups, $token);
|
||||
while ($tok !== false) {
|
||||
$this->groups[] = $tok;
|
||||
$tok = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
public function setExcludeGroups($excludeGroups)
|
||||
{
|
||||
$token = ' ,;';
|
||||
$this->excludeGroups = array();
|
||||
$tok = strtok($excludeGroups, $token);
|
||||
while ($tok !== false) {
|
||||
$this->excludeGroups[] = $tok;
|
||||
$tok = strtok($token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new formatter to all tests of this task.
|
||||
*
|
||||
* @param FormatterElement formatter element
|
||||
*/
|
||||
public function addFormatter(FormatterElement $fe)
|
||||
{
|
||||
$fe->setParent($this);
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main entry point
|
||||
*
|
||||
* @throws BuildException
|
||||
*/
|
||||
public function main()
|
||||
{
|
||||
if ($this->codecoverage && !extension_loaded('xdebug'))
|
||||
{
|
||||
throw new Exception("PHPUnitTask depends on Xdebug being installed to gather code coverage information.");
|
||||
}
|
||||
|
||||
if ($this->printsummary)
|
||||
{
|
||||
$fe = new FormatterElement();
|
||||
$fe->setParent($this);
|
||||
$fe->setType("summary");
|
||||
$fe->setUseFile(false);
|
||||
$this->formatters[] = $fe;
|
||||
}
|
||||
|
||||
if ($this->bootstrap)
|
||||
{
|
||||
require_once $this->bootstrap;
|
||||
}
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
|
||||
if ($fe->getUseFile())
|
||||
{
|
||||
$destFile = new PhingFile($fe->getToDir(), $fe->getOutfile());
|
||||
|
||||
$writer = new FileWriter($destFile->getAbsolutePath());
|
||||
|
||||
$formatter->setOutput($writer);
|
||||
}
|
||||
else
|
||||
{
|
||||
$formatter->setOutput($this->getDefaultOutput());
|
||||
}
|
||||
|
||||
$formatter->startTestRun();
|
||||
}
|
||||
|
||||
foreach ($this->batchtests as $batchtest)
|
||||
{
|
||||
$this->execute($batchtest->getTestSuite());
|
||||
}
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
$formatter->endTestRun();
|
||||
}
|
||||
|
||||
if ($this->testfailed)
|
||||
{
|
||||
throw new BuildException($this->testfailuremessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BuildException
|
||||
*/
|
||||
protected function execute($suite)
|
||||
{
|
||||
$runner = new PHPUnitTestRunner($this->project, $this->groups, $this->excludeGroups);
|
||||
|
||||
$runner->setCodecoverage($this->codecoverage);
|
||||
$runner->setUseCustomErrorHandler($this->usecustomerrorhandler);
|
||||
|
||||
foreach ($this->formatters as $fe)
|
||||
{
|
||||
$formatter = $fe->getFormatter();
|
||||
|
||||
$runner->addFormatter($formatter);
|
||||
}
|
||||
|
||||
$runner->run($suite);
|
||||
|
||||
$retcode = $runner->getRetCode();
|
||||
|
||||
if ($retcode == PHPUnitTestRunner::ERRORS) {
|
||||
if ($this->errorproperty) {
|
||||
$this->project->setNewProperty($this->errorproperty, true);
|
||||
}
|
||||
if ($this->haltonerror) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
} elseif ($retcode == PHPUnitTestRunner::FAILURES) {
|
||||
if ($this->failureproperty) {
|
||||
$this->project->setNewProperty($this->failureproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonfailure) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
} elseif ($retcode == PHPUnitTestRunner::INCOMPLETES) {
|
||||
if ($this->incompleteproperty) {
|
||||
$this->project->setNewProperty($this->incompleteproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonincomplete) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
} elseif ($retcode == PHPUnitTestRunner::SKIPPED) {
|
||||
if ($this->skippedproperty) {
|
||||
$this->project->setNewProperty($this->skippedproperty, true);
|
||||
}
|
||||
|
||||
if ($this->haltonskipped) {
|
||||
$this->testfailed = true;
|
||||
$this->testfailuremessage = $runner->getLastFailureMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getDefaultOutput()
|
||||
{
|
||||
return new LogWriter($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a set of tests based on pattern matching.
|
||||
*
|
||||
* @return BatchTest a new instance of a batch test.
|
||||
*/
|
||||
public function createBatchTest()
|
||||
{
|
||||
$batchtest = new BatchTest($this->getProject());
|
||||
|
||||
$this->batchtests[] = $batchtest;
|
||||
|
||||
return $batchtest;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitTestRunner.php 906 2010-10-05 18:01:43Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
// phpunit 3.5 ships with autoloader
|
||||
// @todo - find out sane model for Phing and PHPUnit autoloaders/hooks co-existense
|
||||
if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >=0) {
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
}
|
||||
require_once 'PHPUnit/Util/ErrorHandler.php';
|
||||
require_once 'PHPUnit/Util/Filter.php';
|
||||
require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
|
||||
require_once 'phing/system/util/Timer.php';
|
||||
|
||||
/**
|
||||
* Simple Testrunner for PHPUnit that runs all tests of a testsuite.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitTestRunner.php 906 2010-10-05 18:01:43Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitTestRunner extends PHPUnit_Runner_BaseTestRunner implements PHPUnit_Framework_TestListener
|
||||
{
|
||||
const SUCCESS = 0;
|
||||
const FAILURES = 1;
|
||||
const ERRORS = 2;
|
||||
const INCOMPLETES = 3;
|
||||
const SKIPPED = 4;
|
||||
|
||||
private $retCode = 0;
|
||||
private $lastFailureMessage = "";
|
||||
private $formatters = array();
|
||||
|
||||
private $codecoverage = false;
|
||||
|
||||
private $project = NULL;
|
||||
|
||||
private $groups = array();
|
||||
private $excludeGroups = array();
|
||||
|
||||
private $useCustomErrorHandler = true;
|
||||
|
||||
public function __construct(Project $project, $groups = array(), $excludeGroups = array())
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->groups = $groups;
|
||||
$this->excludeGroups = $excludeGroups;
|
||||
$this->retCode = self::SUCCESS;
|
||||
}
|
||||
|
||||
public function setCodecoverage($codecoverage)
|
||||
{
|
||||
$this->codecoverage = $codecoverage;
|
||||
}
|
||||
|
||||
public function setUseCustomErrorHandler($useCustomErrorHandler)
|
||||
{
|
||||
$this->useCustomErrorHandler = $useCustomErrorHandler;
|
||||
}
|
||||
|
||||
public function addFormatter($formatter)
|
||||
{
|
||||
$this->formatters[] = $formatter;
|
||||
}
|
||||
|
||||
public static function handleError($level, $message, $file, $line)
|
||||
{
|
||||
$isFiltered = false;
|
||||
if (version_compare(PHPUnit_Runner_Version::id(), '3.5.0') >=0) {
|
||||
$isFiltered = PHP_CodeCoverage::getInstance()->filter()->isFiltered(
|
||||
$file, array(), true
|
||||
);
|
||||
} else {
|
||||
$isFiltered = PHPUnit_Util_Filter::isFiltered($file, true, true);
|
||||
}
|
||||
if (!$isFiltered) {
|
||||
return PHPUnit_Util_ErrorHandler::handleError($level, $message, $file, $line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a test
|
||||
*/
|
||||
public function run(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
$res = new PHPUnit_Framework_TestResult();
|
||||
|
||||
if ($this->codecoverage)
|
||||
{
|
||||
$res->collectCodeCoverageInformation(TRUE);
|
||||
}
|
||||
|
||||
$res->addListener($this);
|
||||
|
||||
foreach ($this->formatters as $formatter)
|
||||
{
|
||||
$res->addListener($formatter);
|
||||
}
|
||||
|
||||
/* Set PHPUnit error handler */
|
||||
if ($this->useCustomErrorHandler)
|
||||
{
|
||||
$oldErrorHandler = set_error_handler(array('PHPUnitTestRunner', 'handleError'), E_ALL | E_STRICT);
|
||||
}
|
||||
|
||||
$suite->run($res, false, $this->groups, $this->excludeGroups);
|
||||
|
||||
foreach ($this->formatters as $formatter)
|
||||
{
|
||||
$formatter->processResult($res);
|
||||
}
|
||||
|
||||
/* Restore Phing error handler */
|
||||
if ($this->useCustomErrorHandler)
|
||||
{
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
if ($this->codecoverage)
|
||||
{
|
||||
$coverage = $res->getCodeCoverage();
|
||||
|
||||
$summary = $coverage->getSummary();
|
||||
|
||||
CoverageMerger::merge($this->project, $summary);
|
||||
}
|
||||
|
||||
if ($res->errorCount() != 0)
|
||||
{
|
||||
$this->retCode = self::ERRORS;
|
||||
}
|
||||
else if ($res->failureCount() != 0)
|
||||
{
|
||||
$this->retCode = self::FAILURES;
|
||||
}
|
||||
else if ($res->notImplementedCount() != 0)
|
||||
{
|
||||
$this->retCode = self::INCOMPLETES;
|
||||
}
|
||||
else if ($res->skippedCount() != 0)
|
||||
{
|
||||
$this->retCode = self::SKIPPED;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRetCode()
|
||||
{
|
||||
return $this->retCode;
|
||||
}
|
||||
|
||||
public function getLastFailureMessage()
|
||||
{
|
||||
return $this->lastFailureMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* An error occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test ERROR (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* A failure occurred.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test FAILURE (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Incomplete test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
*/
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test INCOMPLETE (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Skipped test.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param Exception $e
|
||||
* @param float $time
|
||||
* @since Method available since Release 3.0.0
|
||||
*/
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->lastFailureMessage = "Test SKIPPED (" . $test->getName() . "): " . $e->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param string $testName
|
||||
*/
|
||||
public function testStarted($testName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param string $testName
|
||||
*/
|
||||
public function testEnded($testName)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test failed.
|
||||
*
|
||||
* @param integer $status
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param PHPUnit_Framework_AssertionFailedError $e
|
||||
*/
|
||||
public function testFailed($status, PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to define how to handle a failed loading of
|
||||
* a test suite.
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
protected function runFailed($message)
|
||||
{
|
||||
throw new BuildException($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite started.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
* @since Method available since Release 2.2.0
|
||||
*/
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test suite ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_TestSuite $suite
|
||||
* @since Method available since Release 2.2.0
|
||||
*/
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test started.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
*/
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param PHPUnit_Framework_Test $test
|
||||
* @param float $time
|
||||
*/
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
141
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitUtil.php
Normal file
141
airtime_mvc/library/phing/tasks/ext/phpunit/PHPUnitUtil.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitUtil.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Various utility functions
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitUtil.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PHPUnitUtil
|
||||
{
|
||||
protected static $definedClasses = array();
|
||||
|
||||
/**
|
||||
* Returns the package of a class as defined in the docblock of the class using @package
|
||||
*
|
||||
* @param string the name of the class
|
||||
* @return string the name of the package
|
||||
*/
|
||||
static function getPackageName($classname)
|
||||
{
|
||||
$reflect = new ReflectionClass($classname);
|
||||
|
||||
if (preg_match('/@package[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches))
|
||||
{
|
||||
return $matches[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subpackage of a class as defined in the docblock of the class
|
||||
* using @subpackage
|
||||
*
|
||||
* @param string $classname the name of the class
|
||||
*
|
||||
* @author Benjamin Schultz <bschultz@proqrent.de>
|
||||
* @return string|null the name of the subpackage
|
||||
*/
|
||||
public static function getSubpackageName($classname)
|
||||
{
|
||||
$reflect = new ReflectionClass($classname);
|
||||
|
||||
if (preg_match('/@subpackage[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches)) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Derives the classname from a filename.
|
||||
* Assumes that there is only one class defined in that particular file, and that
|
||||
* the naming follows the dot-path (Java) notation scheme.
|
||||
*
|
||||
* @param string the filename
|
||||
* @return string the name fo the class
|
||||
*/
|
||||
public static function getClassFromFileName($filename)
|
||||
{
|
||||
$filename = basename($filename);
|
||||
|
||||
$rpos = strrpos($filename, '.');
|
||||
|
||||
if ($rpos != -1)
|
||||
{
|
||||
$filename = substr($filename, 0, $rpos);
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string the filename
|
||||
* @param Path optional classpath
|
||||
* @return array list of classes defined in the file
|
||||
*/
|
||||
public static function getDefinedClasses($filename, $classpath = NULL)
|
||||
{
|
||||
$filename = realpath($filename);
|
||||
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
throw new Exception("File '" . $filename . "' does not exist");
|
||||
}
|
||||
|
||||
if (isset(self::$definedClasses[$filename]))
|
||||
{
|
||||
return self::$definedClasses[$filename];
|
||||
}
|
||||
|
||||
Phing::__import($filename, $classpath);
|
||||
|
||||
$declaredClasses = get_declared_classes();
|
||||
|
||||
foreach ($declaredClasses as $classname)
|
||||
{
|
||||
$reflect = new ReflectionClass($classname);
|
||||
|
||||
self::$definedClasses[$reflect->getFilename()][] = $classname;
|
||||
|
||||
if (is_array(self::$definedClasses[$reflect->getFilename()]))
|
||||
{
|
||||
self::$definedClasses[$reflect->getFilename()] = array_unique(self::$definedClasses[$reflect->getFilename()]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset(self::$definedClasses[$filename]))
|
||||
{
|
||||
return self::$definedClasses[$filename];
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: CloverPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPUnit/Util/Log/JUnit.php';
|
||||
require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Clover.php';
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints Clover XML output of the test
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: CloverPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.formatter
|
||||
* @since 2.4.0
|
||||
*/
|
||||
class CloverPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
/**
|
||||
* @var PHPUnit_Util_Log_CodeCoverage_XML_Clover
|
||||
*/
|
||||
private $clover = NULL;
|
||||
|
||||
/**
|
||||
* @var PHPUnit_Framework_TestResult
|
||||
*/
|
||||
private $result = NULL;
|
||||
|
||||
public function __construct(PHPUnitTask $parentTask)
|
||||
{
|
||||
parent::__construct($parentTask);
|
||||
|
||||
$this->clover = new PHPUnit_Util_Log_CodeCoverage_XML_Clover(null);
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return ".xml";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "clover-coverage";
|
||||
}
|
||||
|
||||
public function processResult(PHPUnit_Framework_TestResult $result)
|
||||
{
|
||||
$this->result = $result;
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
ob_start();
|
||||
$this->clover->process($this->result);
|
||||
$contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if ($this->out)
|
||||
{
|
||||
$this->out->write($contents);
|
||||
$this->out->close();
|
||||
}
|
||||
|
||||
parent::endTestRun();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPUnit/Framework/TestListener.php';
|
||||
|
||||
require_once 'phing/system/io/Writer.php';
|
||||
|
||||
/**
|
||||
* This abstract class describes classes that format the results of a PHPUnit testrun.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
abstract class PHPUnitResultFormatter implements PHPUnit_Framework_TestListener
|
||||
{
|
||||
protected $out = NULL;
|
||||
|
||||
protected $project = NULL;
|
||||
|
||||
private $timers = false;
|
||||
|
||||
private $runCounts = false;
|
||||
|
||||
private $failureCounts = false;
|
||||
|
||||
private $errorCounts = false;
|
||||
|
||||
private $incompleteCounts = false;
|
||||
|
||||
private $skipCounts = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param PHPUnitTask $parentTask Calling Task
|
||||
*/
|
||||
public function __construct(PHPUnitTask $parentTask)
|
||||
{
|
||||
$this->project = $parentTask->getProject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the writer the formatter is supposed to write its results to.
|
||||
*/
|
||||
public function setOutput(Writer $out)
|
||||
{
|
||||
$this->out = $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the extension used for this formatter
|
||||
*
|
||||
* @return string the extension
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public function processResult(PHPUnit_Framework_TestResult $result)
|
||||
{
|
||||
}
|
||||
|
||||
public function startTestRun()
|
||||
{
|
||||
$this->timers = array($this->getMicrotime());
|
||||
$this->runCounts = array(0);
|
||||
$this->failureCounts = array(0);
|
||||
$this->errorCounts = array(0);
|
||||
$this->incompleteCounts = array(0);
|
||||
$this->skipCounts = array(0);
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
$this->timers[] = $this->getMicrotime();
|
||||
$this->runCounts[] = 0;
|
||||
$this->failureCounts[] = 0;
|
||||
$this->errorCounts[] = 0;
|
||||
$this->incompleteCounts[] = 0;
|
||||
$this->skipCounts[] = 0;
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
$lastRunCount = array_pop($this->runCounts);
|
||||
$this->runCounts[count($this->runCounts) - 1] += $lastRunCount;
|
||||
|
||||
$lastFailureCount = array_pop($this->failureCounts);
|
||||
$this->failureCounts[count($this->failureCounts) - 1] += $lastFailureCount;
|
||||
|
||||
$lastErrorCount = array_pop($this->errorCounts);
|
||||
$this->errorCounts[count($this->errorCounts) - 1] += $lastErrorCount;
|
||||
|
||||
$lastIncompleteCount = array_pop($this->incompleteCounts);
|
||||
$this->incompleteCounts[count($this->incompleteCounts) - 1] += $lastIncompleteCount;
|
||||
|
||||
$lastSkipCount = array_pop($this->skipCounts);
|
||||
$this->skipCounts[count($this->skipCounts) - 1] += $lastSkipCount;
|
||||
|
||||
array_pop($this->timers);
|
||||
}
|
||||
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
{
|
||||
$this->runCounts[count($this->runCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->errorCounts[count($this->errorCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
$this->failureCounts[count($this->failureCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->incompleteCounts[count($this->incompleteCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
$this->skipCounts[count($this->skipCounts) - 1]++;
|
||||
}
|
||||
|
||||
public function getRunCount()
|
||||
{
|
||||
return end($this->runCounts);
|
||||
}
|
||||
|
||||
public function getFailureCount()
|
||||
{
|
||||
return end($this->failureCounts);
|
||||
}
|
||||
|
||||
public function getErrorCount()
|
||||
{
|
||||
return end($this->errorCounts);
|
||||
}
|
||||
|
||||
public function getIncompleteCount()
|
||||
{
|
||||
return end($this->incompleteCounts);
|
||||
}
|
||||
|
||||
public function getSkippedCount()
|
||||
{
|
||||
return end($this->skipCounts);
|
||||
}
|
||||
|
||||
public function getElapsedTime()
|
||||
{
|
||||
if (end($this->timers))
|
||||
{
|
||||
return $this->getMicrotime() - end($this->timers);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private function getMicrotime() {
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
return (float)$usec + (float)$sec;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: PlainPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints plain text output of the test to a specified Writer.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: PlainPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.phpunit.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class PlainPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
private $inner = "";
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return ".txt";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "testresults";
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::startTestSuite($suite);
|
||||
|
||||
$this->inner = "";
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
foreach ($suite->tests() as $test)
|
||||
{
|
||||
if ($test instanceof PHPUnit_Framework_TestSuite)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$sb = "Testsuite: " . $suite->getName() . "\n";
|
||||
$sb.= "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Incomplete: " . $this->getIncompleteCount();
|
||||
$sb.= ", Skipped: " . $this->getSkippedCount();
|
||||
$sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n";
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->write($sb);
|
||||
$this->out->write($this->inner);
|
||||
}
|
||||
|
||||
parent::endTestSuite($suite);
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addError($test, $e, $time);
|
||||
|
||||
$this->formatError("ERROR", $test, $e);
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
parent::addFailure($test, $e, $time);
|
||||
$this->formatError("FAILED", $test, $e);
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addIncompleteTest($test, $e, $time);
|
||||
|
||||
$this->formatError("INCOMPLETE", $test);
|
||||
}
|
||||
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addSkippedTest($test, $e, $time);
|
||||
$this->formatError("SKIPPED", $test);
|
||||
}
|
||||
|
||||
private function formatError($type, PHPUnit_Framework_Test $test, Exception $e = null)
|
||||
{
|
||||
if ($test != null)
|
||||
{
|
||||
$this->endTest($test, time());
|
||||
}
|
||||
|
||||
$this->inner.= $test->getName() . " " . $type . "\n";
|
||||
|
||||
if ($e !== null) {
|
||||
$this->inner.= $e->getMessage() . "\n";
|
||||
$this->inner.= PHPUnit_Util_Filter::getFilteredStackTrace($e, false) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
parent::endTestRun();
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: SummaryPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints short summary output of the test to Phing's logging system.
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: SummaryPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class SummaryPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::endTestSuite($suite);
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
parent::endTestRun();
|
||||
|
||||
$sb = "Tests run: " . $this->getRunCount();
|
||||
$sb.= ", Failures: " . $this->getFailureCount();
|
||||
$sb.= ", Errors: " . $this->getErrorCount();
|
||||
$sb.= ", Incomplete: " . $this->getIncompleteCount();
|
||||
$sb.= ", Skipped: " . $this->getSkippedCount();
|
||||
$sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n";
|
||||
|
||||
if ($this->out != NULL)
|
||||
{
|
||||
$this->out->write($sb);
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/**
|
||||
* $Id: XMLPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
*
|
||||
* 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 'PHPUnit/Util/Log/JUnit.php';
|
||||
|
||||
require_once 'phing/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
|
||||
|
||||
/**
|
||||
* Prints XML output of the test to a specified Writer
|
||||
*
|
||||
* @author Michiel Rook <michiel.rook@gmail.com>
|
||||
* @version $Id: XMLPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $
|
||||
* @package phing.tasks.ext.formatter
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class XMLPHPUnitResultFormatter extends PHPUnitResultFormatter
|
||||
{
|
||||
/**
|
||||
* @var PHPUnit_Util_Log_JUnit
|
||||
*/
|
||||
private $logger = NULL;
|
||||
|
||||
public function __construct(PHPUnitTask $parentTask)
|
||||
{
|
||||
parent::__construct($parentTask);
|
||||
|
||||
$logIncompleteSkipped = $parentTask->getHaltonincomplete() || $parentTask->getHaltonskipped();
|
||||
|
||||
$this->logger = new PHPUnit_Util_Log_JUnit(null, $logIncompleteSkipped);
|
||||
$this->logger->setWriteDocument(false);
|
||||
}
|
||||
|
||||
public function getExtension()
|
||||
{
|
||||
return ".xml";
|
||||
}
|
||||
|
||||
public function getPreferredOutfile()
|
||||
{
|
||||
return "testsuites";
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::startTestSuite($suite);
|
||||
|
||||
$this->logger->startTestSuite($suite);
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
parent::endTestSuite($suite);
|
||||
|
||||
$this->logger->endTestSuite($suite);
|
||||
}
|
||||
|
||||
public function startTest(PHPUnit_Framework_Test $test)
|
||||
{
|
||||
parent::startTest($test);
|
||||
|
||||
$this->logger->startTest($test);
|
||||
}
|
||||
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
parent::endTest($test, $time);
|
||||
|
||||
$this->logger->endTest($test, $time);
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addError($test, $e, $time);
|
||||
|
||||
$this->logger->addError($test, $e, $time);
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
parent::addFailure($test, $e, $time);
|
||||
|
||||
$this->logger->addFailure($test, $e, $time);
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
|
||||
{
|
||||
parent::addIncompleteTest($test, $e, $time);
|
||||
|
||||
$this->logger->addIncompleteTest($test, $e, $time);
|
||||
}
|
||||
|
||||
public function endTestRun()
|
||||
{
|
||||
parent::endTestRun();
|
||||
|
||||
if ($this->out)
|
||||
{
|
||||
$this->out->write($this->logger->getXML());
|
||||
$this->out->close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue