Source for file XML.php
Documentation is available at XML.php
// +------------------------------------------------------------------------+
// +------------------------------------------------------------------------+
// | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// $Id: XML.php,v 1.8.2.4 2005/02/17 15:41:30 sebastian Exp $
require_once 'Benchmark/Timer.php';
require_once 'PHPUnit2/Framework/AssertionFailedError.php';
require_once 'PHPUnit2/Framework/Test.php';
require_once 'PHPUnit2/Framework/TestFailure.php';
require_once 'PHPUnit2/Framework/TestListener.php';
require_once 'PHPUnit2/Framework/TestResult.php';
require_once 'PHPUnit2/Framework/TestSuite.php';
require_once 'PHPUnit2/Util/Filter.php';
require_once 'PHPUnit2/Util/Printer.php';
* A TestListener that generates an XML-based logfile
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
// {{{ Instance Variables
private $writeDocument = TRUE;
private $testSuites = array ();
private $testSuiteTests = array (0 );
private $testSuiteErrors = array (0 );
private $testSuiteFailures = array (0 );
private $testSuiteTimes = array (0 );
private $testSuiteLevel = 0;
private $currentTestCase = NULL;
// {{{ public function __construct($out = NULL)
$this->document = new DOMDocument ('1.0', 'UTF-8');
$this->document->formatOutput = TRUE;
$this->root = $this->document->createElement ('testsuites');
$this->document->appendChild ($this->root);
$this->timer = new Benchmark_Timer;
// {{{ public function __destruct()
if ($this->writeDocument === TRUE ) {
// {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
* @param PHPUnit2_Framework_Test $test
public function addError(PHPUnit2_Framework_Test $test, Exception $e) {
$error->setAttribute ('message', $e->getMessage ());
$this->currentTestCase->appendChild ($error);
$this->testSuiteErrors[$this->testSuiteLevel]++;
// {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
* @param PHPUnit2_Framework_Test $test
* @param PHPUnit2_Framework_AssertionFailedError $e
public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) {
$failure->setAttribute ('message', $e->getMessage ());
$failure->setAttribute ('type', get_class($e));
$this->currentTestCase->appendChild ($failure);
$this->testSuiteFailures[$this->testSuiteLevel]++;
// {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
* @param PHPUnit2_Framework_Test $test
$error->setAttribute ('message', 'Incomplete Test');
$this->currentTestCase->appendChild ($error);
$this->testSuiteErrors[$this->testSuiteLevel]++;
// {{{ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite)
* @param PHPUnit2_Framework_TestSuite $suite
$testSuite = $this->document->createElement ('testsuite');
$testSuite->setAttribute ('name', $suite->getName ());
$class = new ReflectionClass ($suite->getName ());
$docComment = $class->getDocComment ();
if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) {
$testSuite->setAttribute ('category', $matches[1 ]);
if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) {
$testSuite->setAttribute ('package', $matches[1 ]);
if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) {
$testSuite->setAttribute ('subpackage', $matches[1 ]);
catch (ReflectionException $e) {
if ($this->testSuiteLevel > 0 ) {
$this->testSuites[$this->testSuiteLevel]->appendChild ($testSuite);
$this->root->appendChild ($testSuite);
$this->testSuites[$this->testSuiteLevel] = $testSuite;
$this->testSuiteTests[$this->testSuiteLevel] = 0;
$this->testSuiteErrors[$this->testSuiteLevel] = 0;
$this->testSuiteFailures[$this->testSuiteLevel] = 0;
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
// {{{ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite)
* @param PHPUnit2_Framework_TestSuite $suite
public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) {
$this->testSuites[$this->testSuiteLevel]->setAttribute ('tests', $this->testSuiteTests[$this->testSuiteLevel]);
$this->testSuites[$this->testSuiteLevel]->setAttribute ('failures', $this->testSuiteFailures[$this->testSuiteLevel]);
$this->testSuites[$this->testSuiteLevel]->setAttribute ('errors', $this->testSuiteErrors[$this->testSuiteLevel]);
$this->testSuites[$this->testSuiteLevel]->setAttribute ('time', $this->testSuiteTimes[$this->testSuiteLevel]);
if ($this->testSuiteLevel > 1 ) {
$this->testSuiteTests[$this->testSuiteLevel - 1 ] += $this->testSuiteTests[$this->testSuiteLevel];
$this->testSuiteErrors[$this->testSuiteLevel - 1 ] += $this->testSuiteErrors[$this->testSuiteLevel];
$this->testSuiteFailures[$this->testSuiteLevel - 1 ] += $this->testSuiteFailures[$this->testSuiteLevel];
$this->testSuiteTimes[$this->testSuiteLevel - 1 ] += $this->testSuiteTimes[$this->testSuiteLevel];
// {{{ public function startTest(PHPUnit2_Framework_Test $test)
* @param PHPUnit2_Framework_Test $test
public function startTest(PHPUnit2_Framework_Test $test) {
$testCase = $this->document->createElement ('testcase');
$testCase->setAttribute ('name', $test->getName ());
$testCase->setAttribute ('class', get_class($test));
$this->testSuites[$this->testSuiteLevel]->appendChild ($testCase);
$this->currentTestCase = $testCase;
$this->testSuiteTests[$this->testSuiteLevel]++;
// {{{ public function endTest(PHPUnit2_Framework_Test $test)
* @param PHPUnit2_Framework_Test $test
public function endTest(PHPUnit2_Framework_Test $test) {
$time = $this->timer->timeElapsed ();
$this->currentTestCase->setAttribute ('time', $time);
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
$this->currentTestCase = NULL;
// {{{ public function getXML()
* Returns the XML as a string.
return $this->document->saveXML ();
// {{{ public function setWriteDocument($flag)
* Enables or disables the writing of the document
* This is a "hack" needed for the integration of
$this->writeDocument = $flag;
* vim600: et sw=2 ts=2 fdm=marker
Documentation generated on Mon, 11 Mar 2019 14:19:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|