Skip to content
Browse files

Initial import.

  • Loading branch information...
0 parents commit 1ea37e20733e0ee26d9ded1dab30c11245503f14 @sebastianbergmann committed Jun 29, 2006
Showing with 10,612 additions and 0 deletions.
  1. +240 −0 Extensions/CodeCoverage/Renderer.php
  2. +175 −0 Extensions/CodeCoverage/Renderer/HTML.php
  3. +100 −0 Extensions/CodeCoverage/Renderer/Text.php
  4. +120 −0 Extensions/ExceptionTestCase.php
  5. +216 −0 Extensions/Log/PEAR.php
  6. +362 −0 Extensions/Log/XML.php
  7. +94 −0 Extensions/PerformanceTestCase.php
  8. +113 −0 Extensions/RepeatedTest.php
  9. +162 −0 Extensions/TestDecorator.php
  10. +147 −0 Extensions/TestDox/NamePrettifier.php
  11. +286 −0 Extensions/TestDox/ResultPrinter.php
  12. +97 −0 Extensions/TestDox/ResultPrinter/HTML.php
  13. +97 −0 Extensions/TestDox/ResultPrinter/Text.php
  14. +92 −0 Extensions/TestSetup.php
  15. +664 −0 Framework/Assert.php
  16. +48 −0 Framework/AssertionFailedError.php
  17. +127 −0 Framework/ComparisonFailure.php
  18. +43 −0 Framework/Error.php
  19. +36 −0 Framework/IncompleteTest.php
  20. +39 −0 Framework/IncompleteTestError.php
  21. +60 −0 Framework/Test.php
  22. +325 −0 Framework/TestCase.php
  23. +139 −0 Framework/TestFailure.php
  24. +121 −0 Framework/TestListener.php
  25. +470 −0 Framework/TestResult.php
  26. +494 −0 Framework/TestSuite.php
  27. +66 −0 Framework/Warning.php
  28. +296 −0 Runner/BaseTestRunner.php
  29. +151 −0 Runner/IncludePathTestCollector.php
  30. +97 −0 Runner/StandardTestSuiteLoader.php
  31. +45 −0 Runner/TestCollector.php
  32. +101 −0 Runner/TestRunListener.php
  33. +56 −0 Runner/TestSuiteLoader.php
  34. +61 −0 Runner/Version.php
  35. +61 −0 Tests/AllTests.php
  36. +55 −0 Tests/DoubleTestCase.php
  37. +38 −0 Tests/Error.php
  38. +83 −0 Tests/Extensions/AllTests.php
  39. +83 −0 Tests/Extensions/ExceptionTestCaseTest.php
  40. +84 −0 Tests/Extensions/ExtensionTest.php
  41. +52 −0 Tests/Extensions/PerformanceTestCaseTest.php
  42. +84 −0 Tests/Extensions/RepeatedTestTest.php
  43. +62 −0 Tests/Extensions/TestDox/AllTests.php
  44. +77 −0 Tests/Extensions/TestDox/NamePrettifierTest.php
  45. +38 −0 Tests/Failure.php
  46. +101 −0 Tests/Framework/AllTests.php
  47. +368 −0 Tests/Framework/AssertTest.php
  48. +134 −0 Tests/Framework/ComparisonFailureTest.php
  49. +159 −0 Tests/Framework/SuiteTest.php
  50. +157 −0 Tests/Framework/TestCaseTest.php
  51. +56 −0 Tests/Framework/TestImplementorTest.php
  52. +107 −0 Tests/Framework/TestListenerTest.php
  53. +38 −0 Tests/InheritedTestCase.php
  54. +59 −0 Tests/Iterator.php
  55. +48 −0 Tests/MockRunner.php
  56. +37 −0 Tests/NoArgTestCaseTest.php
  57. +35 −0 Tests/NoTestCaseClass.php
  58. +37 −0 Tests/NoTestCases.php
  59. +36 −0 Tests/NonStatic.php
  60. +40 −0 Tests/NotPublicTestCase.php
  61. +35 −0 Tests/NotVoidTestCase.php
  62. +40 −0 Tests/OneTestCase.php
  63. +38 −0 Tests/OverrideTestCase.php
  64. +69 −0 Tests/Runner/AllTests.php
  65. +42 −0 Tests/Runner/BaseTestRunnerTest.php
  66. +38 −0 Tests/SetupFailure.php
  67. +38 −0 Tests/Sleep.php
  68. +37 −0 Tests/Success.php
  69. +38 −0 Tests/TearDownFailure.php
  70. +38 −0 Tests/ThrowExceptionTestCase.php
  71. +37 −0 Tests/ThrowNoExceptionTestCase.php
  72. +40 −0 Tests/TornDown.php
  73. +44 −0 Tests/TornDown2.php
  74. +43 −0 Tests/TornDown3.php
  75. +38 −0 Tests/TornDown4.php
  76. +38 −0 Tests/TornDown5.php
  77. +40 −0 Tests/WasRun.php
  78. +383 −0 TextUI/ResultPrinter.php
  79. +637 −0 TextUI/TestRunner.php
  80. +247 −0 Util/Filter.php
  81. +89 −0 Util/Printer.php
  82. +301 −0 Util/Skeleton.php
  83. +355 −0 package.xml
  84. +20 −0 pear-phpunit
  85. +18 −0 pear-phpunit.bat
240 Extensions/CodeCoverage/Renderer.php
@@ -0,0 +1,240 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: Renderer.php 539 2006-02-13 16:08:42Z sb $
+//
+
+/**
+ * Abstract base class for Code Coverage renderers.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ * @abstract
+ */
+abstract class PHPUnit2_Extensions_CodeCoverage_Renderer {
+ // {{{ Instance Variables
+
+ /**
+ * @var array
+ * @access protected
+ */
+ protected $codeCoverageInformation;
+
+ /**
+ * @var boolean
+ * @access protected
+ */
+ protected $useSummary = TRUE;
+
+ // }}}
+ // {{{ protected function __construct($codeCoverageInformation)
+
+ /**
+ * Constructor.
+ *
+ * @param array $codeCoverageInformation
+ * @access protected
+ */
+ protected function __construct($codeCoverageInformation) {
+ $this->codeCoverageInformation = $codeCoverageInformation;
+ }
+
+ // }}}
+ // {{{ public function factory($rendererName, $codeCoverageInformation)
+
+ /**
+ * Abstract Factory.
+ *
+ * @param string $rendererName
+ * @param array $codeCoverageInformation
+ * @access public
+ */
+ public function factory($rendererName, $codeCoverageInformation) {
+ $class = 'PHPUnit2_Extensions_CodeCoverage_Renderer_' . $rendererName;
+
+ @require_once 'PHPUnit2/Extensions/CodeCoverage/Renderer/' . $rendererName . '.php';
+
+ if (class_exists($class)) {
+ return new $class($codeCoverageInformation);
+ } else {
+ throw new Exception(
+ sprintf(
+ 'Could not load class %s.',
+ $class
+ )
+ );
+ }
+ }
+
+ // }}}
+ // {{{ public final function render()
+
+ /**
+ * Visualizes the result array of
+ * PHPUnit2_Framework_TestResult::getCodeCoverageInformation().
+ *
+ * @return string
+ * @access public
+ * @final
+ */
+ public final function render() {
+ $buffer = $this->header();
+
+ if ($this->useSummary) {
+ foreach ($this->getSummary() as $sourceFile => $executedLines) {
+ $buffer .= $this->startSourceFile($sourceFile);
+ $buffer .= $this->renderSourceFile(file($sourceFile), $executedLines);
+ $buffer .= $this->endSourceFile($sourceFile);
+ }
+ } else {
+ }
+
+ return $buffer . $this->footer();
+ }
+
+ // }}}
+ // {{{ public function renderToFile($filename)
+
+ /**
+ * Visualizes the result array of
+ * PHPUnit2_Framework_TestResult::getCodeCoverageInformation()
+ * and writes it to a file.
+ *
+ * @param string $filename
+ * @access public
+ * @since 2.2.0
+ */
+ public function renderToFile($filename) {
+ if ($fp = fopen($filename, 'w')) {
+ fputs(
+ $fp,
+ $this->render()
+ );
+
+ fclose($fp);
+ }
+ }
+
+ // }}}
+ // {{{ protected function getSummary()
+
+ /**
+ * Returns summarized Code Coverage data.
+ *
+ * Format of the result array:
+ *
+ * <code>
+ * array(
+ * "/tested/code.php" => array(
+ * linenumber => flag
+ * )
+ * )
+ * </code>
+ *
+ * flag > 1: line was executed.
+ * flag < 1: line is executable but was not executed.
+ *
+ * @return array
+ * @access protected
+ * @since 2.2.0
+ */
+ protected function getSummary() {
+ $summary = array();
+
+ foreach ($this->codeCoverageInformation as $testCaseName => $sourceFiles) {
+ foreach ($sourceFiles as $sourceFile => $executedLines) {
+ foreach ($executedLines as $lineNumber => $flag) {
+ if (!isset($summary[$sourceFile][$lineNumber])) {
+ $summary[$sourceFile][$lineNumber] = $flag;
+ }
+
+ else if ($flag > 0) {
+ $summary[$sourceFile][$lineNumber] = $flag;
+ }
+ }
+ }
+ }
+
+ return $summary;
+ }
+
+ // }}}
+ // {{{ protected function header()
+
+ /**
+ * @return string
+ * @access protected
+ * @since 2.1.1
+ */
+ protected function header() {
+ }
+
+ // }}}
+ // {{{ protected function footer()
+
+ /**
+ * @return string
+ * @access protected
+ * @since 2.1.1
+ */
+ protected function footer() {
+ }
+
+ // }}}
+ // {{{ protected function startSourceFile($sourceFile)
+
+ /**
+ * @param string $sourceFile
+ * @return string
+ * @access protected
+ */
+ protected function startSourceFile($sourceFile) {
+ }
+
+ // }}}
+ // {{{ protected function endSourceFile($sourceFile)
+
+ /**
+ * @param string $sourceFile
+ * @return string
+ * @access protected
+ */
+ protected function endSourceFile($sourceFile) {
+ }
+
+ // }}}
+ // {{{ abstract protected function renderSourceFile($codeLines, $executedLines)
+
+ /**
+ * @param array $codeLines
+ * @param array $executedLines
+ * @return string
+ * @access protected
+ * @abstract
+ */
+ abstract protected function renderSourceFile($codeLines, $executedLines);
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
175 Extensions/CodeCoverage/Renderer/HTML.php
@@ -0,0 +1,175 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: HTML.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Extensions/CodeCoverage/Renderer.php';
+
+/**
+ * Renders Code Coverage information in HTML format.
+ *
+ * Formatting of the generated HTML can be achieved through
+ * CSS (codecoverage.css).
+ *
+ * Example
+ *
+ * <code>
+ * td.ccLineNumber, td.ccCoveredLine, td.ccUncoveredLine, td.ccNotExecutableLine {
+ * font-family: monospace;
+ * white-space: pre;
+ * }
+ *
+ * td.ccLineNumber, td.ccCoveredLine {
+ * background-color: #aaaaaa;
+ * }
+ *
+ * td.ccNotExecutableLine {
+ * color: #aaaaaa;
+ * }
+ * </code>
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_CodeCoverage_Renderer_HTML extends PHPUnit2_Extensions_CodeCoverage_Renderer {
+ // {{{ Constants
+
+ const pageHeader =
+'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link href="codecoverage.css" type="text/css" rel="stylesheet" />
+ </head>
+ <body>
+';
+
+ const pageFooter =
+' </body>
+</html>
+';
+
+ const sourceFileHeader =
+' <table style="border: 1px solid black" cellspacing="0" cellpadding="0" width="100%">
+';
+
+ const sourceFileFooter =
+' </table>
+';
+
+ const codeLine =
+' <tr><td class="ccLineNumber">%s</td><td class="%s">%s</td></tr>
+';
+
+ // }}}
+ // {{{ protected function header()
+
+ /**
+ * @return string
+ * @access protected
+ * @since 2.1.1
+ */
+ protected function header() {
+ return self::pageHeader;
+ }
+
+ // }}}
+ // {{{ protected function footer()
+
+ /**
+ * @return string
+ * @access protected
+ * @since 2.1.1
+ */
+ protected function footer() {
+ return self::pageFooter;
+ }
+
+ // }}}
+ // {{{ protected function startSourceFile($sourceFile)
+
+ /**
+ * @param string $sourceFile
+ * @return string
+ * @access protected
+ */
+ protected function startSourceFile($sourceFile) {
+ return self::sourceFileHeader;
+ }
+
+ // }}}
+ // {{{ protected function endSourceFile($sourceFile)
+
+ /**
+ * @param string $sourceFile
+ * @return string
+ * @access protected
+ */
+ protected function endSourceFile($sourceFile) {
+ return self::sourceFileFooter;
+ }
+
+ // }}}
+ // {{{ protected function renderSourceFile($codeLines, $executedLines)
+
+ /**
+ * @param array $codeLines
+ * @param array $executedLines
+ * @return string
+ * @access protected
+ */
+ protected function renderSourceFile($codeLines, $executedLines) {
+ $buffer = '';
+ $line = 1;
+
+ foreach ($codeLines as $codeLine) {
+ $lineStyle = 'ccNotExecutableLine';
+
+ if (isset($executedLines[$line])) {
+ if ($executedLines[$line] > 0) {
+ $lineStyle = 'ccCoveredLine';
+ } else {
+ $lineStyle = 'ccUncoveredLine';
+ }
+ }
+
+ $buffer .= sprintf(
+ self::codeLine,
+
+ $line,
+ $lineStyle,
+ htmlspecialchars(rtrim($codeLine))
+ );
+
+ $line++;
+ }
+
+ return $buffer;
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
100 Extensions/CodeCoverage/Renderer/Text.php
@@ -0,0 +1,100 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: Text.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Extensions/CodeCoverage/Renderer.php';
+
+/**
+ * Renders Code Coverage information in text format.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_CodeCoverage_Renderer_Text extends PHPUnit2_Extensions_CodeCoverage_Renderer {
+ // {{{ protected function startSourceFile($sourceFile)
+
+ /**
+ * @param string $sourceFile
+ * @return string
+ * @access protected
+ */
+ protected function startSourceFile($sourceFile) {
+ return ' ' . $sourceFile . "\n\n";
+ }
+
+ // }}}
+ // {{{ protected function endSourceFile($sourceFile)
+
+ /**
+ * @param string $sourceFile
+ * @return string
+ * @access protected
+ */
+ protected function endSourceFile($sourceFile) {
+ return "\n";
+ }
+
+ // }}}
+ // {{{ protected function renderSourceFile($codeLines, $executedLines)
+
+ /**
+ * @param array $codeLines
+ * @param array $executedLines
+ * @return string
+ * @access protected
+ */
+ protected function renderSourceFile($codeLines, $executedLines) {
+ $buffer = '';
+ $line = 1;
+
+ foreach ($codeLines as $codeLine) {
+ $flag = '-';
+
+ if (isset($executedLines[$line])) {
+ if ($executedLines[$line] > 0) {
+ $flag = '+';
+ } else {
+ $flag = '#';
+ }
+ }
+
+ $buffer .= sprintf(
+ ' %4u|%s| %s',
+
+ $line,
+ $flag,
+ $codeLine
+ );
+
+ $line++;
+ }
+
+ return $buffer;
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
120 Extensions/ExceptionTestCase.php
@@ -0,0 +1,120 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: ExceptionTestCase.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Framework/TestCase.php';
+
+/**
+ * A TestCase that expects an Exception of class
+ * fExpected to be thrown.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ */
+class PHPUnit2_Extensions_ExceptionTestCase extends PHPUnit2_Framework_TestCase {
+ // {{{ Instance Variables
+
+ /**
+ * The name of the expected Exception.
+ *
+ * @var string
+ * @access private
+ */
+ private $expectedException = '';
+
+ // }}}
+ // {{{ public function __construct($name, $exceptionName = '')
+
+ /**
+ * @param string $name
+ * @param string $exceptionName
+ * @access public
+ */
+ public function __construct($name, $exceptionName = '') {
+ parent::__construct($name);
+
+ if (!empty($exceptionName)) {
+ $this->setExpectedException($exceptionName);
+ }
+ }
+
+ // }}}
+ // {{{ public function getExpectedException()
+
+ /**
+ * @return string
+ * @access public
+ * @since 2.2.0
+ */
+ public function getExpectedException() {
+ return $this->expectedException;
+ }
+
+ // }}}
+ // {{{ public function setExpectedException($exceptionName)
+
+ /**
+ * @param string $exceptionName
+ * @access public
+ * @since 2.2.0
+ */
+ public function setExpectedException($exceptionName) {
+ if (is_string($exceptionName) && class_exists($exceptionName)) {
+ $this->expectedException = $exceptionName;
+ } else {
+ throw new Exception(
+ sprintf(
+ 'Exception %s does not exist.',
+ $exceptionName
+ )
+ );
+ }
+ }
+
+ // }}}
+ // {{{ protected function runTest()
+
+ /**
+ * @access protected
+ */
+ protected function runTest() {
+ try {
+ parent::runTest();
+ }
+
+ catch (Exception $e) {
+ if ($e instanceof $this->expectedException) {
+ return;
+ } else {
+ throw $e;
+ }
+ }
+
+ $this->fail('Expected exception ' . $this->expectedException);
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
216 Extensions/Log/PEAR.php
@@ -0,0 +1,216 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: PEAR.php 539 2006-02-13 16:08:42Z sb $
+//
+
+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';
+
+@include_once 'Log.php';
+
+/**
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_Log_PEAR implements PHPUnit2_Framework_TestListener {
+ // {{{ Instance Variables
+
+ /**
+ * Log.
+ *
+ * @var Log
+ * @access private
+ */
+ private $log;
+
+ // }}}
+ // {{{ public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG)
+
+ /**
+ * @param string $type The type of concrete Log subclass to use.
+ * Currently, valid values are 'console',
+ * 'syslog', 'sql', 'file', and 'mcal'.
+ * @param string $name The name of the actually log file, table, or
+ * other specific store to use. Defaults to an
+ * empty string, with which the subclass will
+ * attempt to do something intelligent.
+ * @param string $ident The identity reported to the log system.
+ * @param array $conf A hash containing any additional configuration
+ * information that a subclass might need.
+ * @param int $maxLevel Maximum priority level at which to log.
+ * @access public
+ */
+ public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) {
+ $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
+ }
+
+ // }}}
+ // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
+
+ /**
+ * An error occurred.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param Exception $e
+ * @access public
+ */
+ public function addError(PHPUnit2_Framework_Test $test, Exception $e) {
+ $this->log->crit(
+ sprintf(
+ 'Test "%s" failed: %s',
+
+ $test->getName(),
+ $e->getMessage()
+ )
+ );
+ }
+
+ // }}}
+ // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
+
+ /**
+ * A failure occurred.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param PHPUnit2_Framework_AssertionFailedError $e
+ * @access public
+ */
+ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) {
+ $this->log->err(
+ sprintf(
+ 'Test "%s" failed: %s',
+
+ $test->getName(),
+ $e->getMessage()
+ )
+ );
+ }
+
+ // }}}
+ // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
+
+ /**
+ * Incomplete test.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param Exception $e
+ * @access public
+ */
+ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) {
+ $this->log->info(
+ sprintf(
+ 'Test "%s" incomplete: %s',
+
+ $test->getName(),
+ $e->getMessage()
+ )
+ );
+ }
+
+ // }}}
+ // {{{ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite)
+
+ /**
+ * A testsuite started.
+ *
+ * @param PHPUnit2_Framework_TestSuite $suite
+ * @access public
+ * @since 2.2.0
+ */
+ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) {
+ $this->log->info(
+ sprintf(
+ 'TestSuite "%s" started.',
+
+ $suite->getName()
+ )
+ );
+ }
+
+ // }}}
+ // {{{ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite)
+
+ /**
+ * A testsuite ended.
+ *
+ * @param PHPUnit2_Framework_TestSuite $suite
+ * @access public
+ * @since 2.2.0
+ */
+ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) {
+ $this->log->info(
+ sprintf(
+ 'TestSuite "%s" ended.',
+
+ $suite->getName()
+ )
+ );
+ }
+
+ // }}}
+ // {{{ public function startTest(PHPUnit2_Framework_Test $test)
+
+ /**
+ * A test started.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ public function startTest(PHPUnit2_Framework_Test $test) {
+ $this->log->info(
+ sprintf(
+ 'Test "%s" started.',
+
+ $test->getName()
+ )
+ );
+ }
+
+ // }}}
+ // {{{ public function endTest(PHPUnit2_Framework_Test $test)
+
+ /**
+ * A test ended.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ public function endTest(PHPUnit2_Framework_Test $test) {
+ $this->log->info(
+ sprintf(
+ 'Test "%s" ended.',
+
+ $test->getName()
+ )
+ );
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
362 Extensions/Log/XML.php
@@ -0,0 +1,362 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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 539 2006-02-13 16:08:42Z sb $
+//
+
+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
+ * of the test execution.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_Log_XML extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener {
+ // {{{ Instance Variables
+
+ /**
+ * @var DOMDocument
+ * @access private
+ */
+ private $document;
+
+ /**
+ * @var DOMElement
+ * @access private
+ */
+ private $root;
+
+ /**
+ * @var boolean
+ * @access private
+ */
+ private $writeDocument = TRUE;
+
+ /**
+ * @var DOMElement[]
+ * @access private
+ */
+ private $testSuites = array();
+
+ /**
+ * @var integer[]
+ * @access private
+ */
+ private $testSuiteTests = array(0);
+
+ /**
+ * @var integer[]
+ * @access private
+ */
+ private $testSuiteErrors = array(0);
+
+ /**
+ * @var integer[]
+ * @access private
+ */
+ private $testSuiteFailures = array(0);
+
+ /**
+ * @var integer[]
+ * @access private
+ */
+ private $testSuiteTimes = array(0);
+
+ /**
+ * @var integer
+ * @access private
+ */
+ private $testSuiteLevel = 0;
+
+ /**
+ * @var DOMElement
+ * @access private
+ */
+ private $currentTestCase = NULL;
+
+ /**
+ * @var Benchmark_Timer
+ * @access private
+ */
+ private $timer;
+
+ // }}}
+ // {{{ public function __construct($out = NULL)
+
+ /**
+ * Constructor.
+ *
+ * @param mixed $out
+ * @access public
+ */
+ 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;
+
+ parent::__construct($out);
+ }
+
+ // }}}
+ // {{{ public function __destruct()
+
+ /**
+ * Destructor.
+ *
+ * @access public
+ */
+ public function __destruct() {
+ if ($this->writeDocument === TRUE) {
+ $this->write($this->getXML());
+ }
+
+ parent::__destruct();
+ }
+
+ // }}}
+ // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
+
+ /**
+ * An error occurred.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param Exception $e
+ * @access public
+ */
+ public function addError(PHPUnit2_Framework_Test $test, Exception $e) {
+ $error = $this->document->createElement('error', PHPUnit2_Util_Filter::getFilteredStacktrace($e));
+ $error->setAttribute('message', $e->getMessage());
+ $error->setAttribute('type', get_class($e));
+
+ $this->currentTestCase->appendChild($error);
+
+ $this->testSuiteErrors[$this->testSuiteLevel]++;
+ }
+
+ // }}}
+ // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
+
+ /**
+ * A failure occurred.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param PHPUnit2_Framework_AssertionFailedError $e
+ * @access public
+ */
+ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) {
+ $failure = $this->document->createElement('failure', PHPUnit2_Util_Filter::getFilteredStacktrace($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)
+
+ /**
+ * Incomplete test.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param Exception $e
+ * @access public
+ */
+ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) {
+ $error = $this->document->createElement('error', PHPUnit2_Util_Filter::getFilteredStacktrace($e));
+ $error->setAttribute('message', 'Incomplete Test');
+ $error->setAttribute('type', get_class($e));
+
+ $this->currentTestCase->appendChild($error);
+
+ $this->testSuiteErrors[$this->testSuiteLevel]++;
+ }
+
+ // }}}
+ // {{{ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite)
+
+ /**
+ * A testsuite started.
+ *
+ * @param PHPUnit2_Framework_TestSuite $suite
+ * @access public
+ * @since 2.2.0
+ */
+ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) {
+ $testSuite = $this->document->createElement('testsuite');
+ $testSuite->setAttribute('name', $suite->getName());
+
+ try {
+ $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);
+ } else {
+ $this->root->appendChild($testSuite);
+ }
+
+ $this->testSuiteLevel++;
+ $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)
+
+ /**
+ * A testsuite ended.
+ *
+ * @param PHPUnit2_Framework_TestSuite $suite
+ * @access public
+ * @since 2.2.0
+ */
+ 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];
+ }
+
+ $this->testSuiteLevel--;
+ }
+
+ // }}}
+ // {{{ public function startTest(PHPUnit2_Framework_Test $test)
+
+ /**
+ * A test started.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ 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]++;
+
+ $this->timer->start();
+ }
+
+ // }}}
+ // {{{ public function endTest(PHPUnit2_Framework_Test $test)
+
+ /**
+ * A test ended.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ public function endTest(PHPUnit2_Framework_Test $test) {
+ $this->timer->stop();
+ $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 string
+ * @access public
+ * @since 2.2.0
+ */
+ public function getXML() {
+ return $this->document->saveXML();
+ }
+
+ // }}}
+ // {{{ public function setWriteDocument($flag)
+
+ /**
+ * Enables or disables the writing of the document
+ * in __destruct().
+ *
+ * This is a "hack" needed for the integration of
+ * PHPUnit with Phing.
+ *
+ * @return string
+ * @access public
+ * @since 2.2.0
+ */
+ public function setWriteDocument($flag) {
+ if (is_bool($flag)) {
+ $this->writeDocument = $flag;
+ }
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
94 Extensions/PerformanceTestCase.php
@@ -0,0 +1,94 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: PerformanceTestCase.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'Benchmark/Timer.php';
+require_once 'PHPUnit2/Framework/TestCase.php';
+
+/**
+ * A TestCase that expects a TestCase to be executed
+ * meeting a given time limit.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_PerformanceTestCase extends PHPUnit2_Framework_TestCase {
+ // {{{ Instance Variables
+
+ /**
+ * @var double
+ * @access private
+ */
+ private $maxRunningTime = 0;
+
+ // }}}
+ // {{{ public function __construct($name, $maxRunningTime = 0)
+
+ /**
+ * @param string $name
+ * @param double $maxRunningTime
+ * @access public
+ */
+ public function __construct($name, $maxRunningTime = 0) {
+ if (is_numeric($maxRunningTime) &&
+ $maxRunningTime >= 0) {
+ $this->maxRunningTime = $maxRunningTime;
+ } else {
+ throw new Exception('Illegal argument.');
+ }
+
+ parent::__construct($name);
+ }
+
+ // }}}
+ // {{{ protected function runTest()
+
+ /**
+ * @access public
+ */
+ protected function runTest() {
+ $timer = new Benchmark_Timer;
+
+ $timer->start();
+ parent::runTest();
+ $timer->stop();
+
+ if ($this->maxRunningTime != 0 &&
+ $timer->timeElapsed() > $this->maxRunningTime) {
+ $this->fail(
+ sprintf(
+ 'expected running time: <= %s but was: %s',
+
+ $this->maxRunningTime,
+ $timer->timeElapsed()
+ )
+ );
+ }
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
113 Extensions/RepeatedTest.php
@@ -0,0 +1,113 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: RepeatedTest.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Framework/Test.php';
+require_once 'PHPUnit2/Framework/TestResult.php';
+require_once 'PHPUnit2/Extensions/TestDecorator.php';
+
+/**
+ * A Decorator that runs a test repeatedly.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ */
+class PHPUnit2_Extensions_RepeatedTest extends PHPUnit2_Extensions_TestDecorator {
+ // {{{ Instance Variables
+
+ /**
+ * @var integer
+ * @access private
+ */
+ private $timesRepeat = 1;
+
+ // }}}
+ // {{{ public function __construct(PHPUnit2_Framework_Test $test, $timesRepeat = 1)
+
+ /**
+ * Constructor.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param integer $timesRepeat
+ * @access public
+ */
+ public function __construct(PHPUnit2_Framework_Test $test, $timesRepeat = 1) {
+ parent::__construct($test);
+
+ if (is_integer($timesRepeat) &&
+ $timesRepeat >= 0) {
+ $this->timesRepeat = $timesRepeat;
+ } else {
+ throw new Exception('Illegal argument.');
+ }
+ }
+
+ // }}}
+ // {{{ public function countTestCases()
+
+ /**
+ * Counts the number of test cases that
+ * will be run by this test.
+ *
+ * @return integer
+ * @access public
+ */
+ public function countTestCases() {
+ return $this->timesRepeat * $this->test->countTestCases();
+ }
+
+ // }}}
+ // {{{ public function run($result = NULL)
+
+ /**
+ * Runs the decorated test and collects the
+ * result in a TestResult.
+ *
+ * @param PHPUnit2_Framework_TestResult $result
+ * @return PHPUnit2_Framework_TestResult
+ * @access public
+ */
+ public function run($result = NULL) {
+ if ($result === NULL) {
+ $result = $this->createResult();
+ }
+
+ // XXX: Workaround for missing ability to declare type-hinted parameters as optional.
+ else if (!($result instanceof PHPUnit2_Framework_TestResult)) {
+ throw new Exception(
+ 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.'
+ );
+ }
+
+ for ($i = 0; $i < $this->timesRepeat && !$result->shouldStop(); $i++) {
+ $this->test->run($result);
+ }
+
+ return $result;
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
162 Extensions/TestDecorator.php
@@ -0,0 +1,162 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 |
+// +------------------------------------------------------------------------+
+// | 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: TestDecorator.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Framework/Assert.php';
+require_once 'PHPUnit2/Framework/Test.php';
+require_once 'PHPUnit2/Framework/TestResult.php';
+
+/**
+ * A Decorator for Tests.
+ *
+ * Use TestDecorator as the base class for defining new
+ * test decorators. Test decorator subclasses can be introduced
+ * to add behaviour before or after a test is run.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ */
+class PHPUnit2_Extensions_TestDecorator extends PHPUnit2_Framework_Assert implements PHPUnit2_Framework_Test {
+ // {{{ Instance Variables
+
+ /**
+ * The Test to be decorated.
+ *
+ * @var object
+ * @access protected
+ */
+ protected $test = NULL;
+
+ // }}}
+ // {{{ public function __construct(PHPUnit2_Framework_Test $test)
+
+ /**
+ * Constructor.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ public function __construct(PHPUnit2_Framework_Test $test) {
+ $this->test = $test;
+ }
+
+ // }}}
+ // {{{ public function toString()
+
+ /**
+ * Returns a string representation of the test.
+ *
+ * @return string
+ * @access public
+ */
+ public function toString() {
+ return $this->test->toString();
+ }
+
+ // }}}
+ // {{{ public function basicRun(PHPUnit2_Framework_TestResult $result)
+
+ /**
+ * Runs the test and collects the
+ * result in a TestResult.
+ *
+ * @param PHPUnit2_Framework_TestResult $result
+ * @access public
+ */
+ public function basicRun(PHPUnit2_Framework_TestResult $result) {
+ $this->test->run($result);
+ }
+
+ // }}}
+ // {{{ public function countTestCases()
+
+ /**
+ * Counts the number of test cases that
+ * will be run by this test.
+ *
+ * @return integer
+ * @access public
+ */
+ public function countTestCases() {
+ return $this->test->countTestCases();
+ }
+
+ // }}}
+ // {{{ protected function createResult()
+
+ /**
+ * Creates a default TestResult object.
+ *
+ * @return PHPUnit2_Framework_TestResult
+ * @access protected
+ */
+ protected function createResult() {
+ return new PHPUnit2_Framework_TestResult;
+ }
+
+ // }}}
+ // {{{ public function getTest()
+
+ /**
+ * Returns the test to be run.
+ *
+ * @return PHPUnit2_Framework_Test
+ * @access public
+ */
+ public function getTest() {
+ return $this->test;
+ }
+
+ // }}}
+ // {{{ public function run($result = NULL)
+
+ /**
+ * Runs the decorated test and collects the
+ * result in a TestResult.
+ *
+ * @param PHPUnit2_Framework_TestResult $result
+ * @return PHPUnit2_Framework_TestResult
+ * @access public
+ */
+ public function run($result = NULL) {
+ if ($result === NULL) {
+ $result = $this->createResult();
+ }
+
+ // XXX: Workaround for missing ability to declare type-hinted parameters as optional.
+ else if (!($result instanceof PHPUnit2_Framework_TestResult)) {
+ throw new Exception(
+ 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.'
+ );
+ }
+
+ $this->basicRun($result);
+
+ return $result;
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
147 Extensions/TestDox/NamePrettifier.php
@@ -0,0 +1,147 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit2 :: TestDox |
+// +------------------------------------------------------------------------+
+// | 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: NamePrettifier.php 539 2006-02-13 16:08:42Z sb $
+//
+
+/**
+ * A prettifier for class names.
+ *
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_TestDox_NamePrettifier {
+ // {{{ Instance Variables
+
+ /**
+ * @var string
+ * @access protected
+ */
+ protected $prefix = 'Test';
+
+ /**
+ * @var string
+ * @access protected
+ */
+ protected $suffix = 'Test';
+
+ // }}}
+ // {{{ public function isATestMethod($testMethodName)
+
+ /**
+ * Tests if a method is a test method.
+ *
+ * @param string $testMethodName
+ * @return boolean
+ * @access public
+ */
+ public function isATestMethod($testMethodName) {
+ if (substr($testMethodName, 0, 4) == 'test') {
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ // }}}
+ // {{{ public function prettifyTestClass($testClassName)
+
+ /**
+ * Prettifies the name of a test class.
+ *
+ * @param string $testClassName
+ * @return string
+ * @access public
+ */
+ public function prettifyTestClass($testClassName) {
+ $title = $testClassName;
+
+ if ($this->suffix !== NULL &&
+ $this->suffix == substr($testClassName, -1 * strlen($this->suffix))) {
+ $title = substr($title, 0, strripos($title, $this->suffix));
+ }
+
+ if ($this->prefix !== NULL &&
+ $this->prefix == substr($testClassName, 0, strlen($this->prefix))) {
+ $title = substr($title, strlen($this->prefix));
+ }
+
+ return $title;
+ }
+
+ // }}}
+ // {{{ public function prettifyTestMethod($testMethodName)
+
+ /**
+ * Prettifies the name of a test method.
+ *
+ * @param string $testMethodName
+ * @return string
+ * @access public
+ */
+ public function prettifyTestMethod($testMethodName) {
+ $buffer = '';
+
+ for ($i = 4; $i < strlen($testMethodName); $i++) {
+ if ($i > 4 &&
+ ord($testMethodName[$i]) >= 65 &&
+ ord($testMethodName[$i]) <= 90) {
+ $buffer .= ' ' . strtolower($testMethodName[$i]);
+ } else {
+ $buffer .= $testMethodName[$i];
+ }
+ }
+
+ return $buffer;
+ }
+
+ // }}}
+ // {{{ public function setPrefix($prefix)
+
+ /**
+ * Sets the prefix of test names.
+ *
+ * @param string $prefix
+ * @access public
+ */
+ public function setPrefix($prefix) {
+ $this->prefix = $prefix;
+ }
+
+ // }}}
+ // {{{ public function setSuffix($suffix)
+
+ /**
+ * Sets the suffix of test names.
+ *
+ * @param string $prefix
+ * @access public
+ */
+ public function setSuffix($suffix) {
+ $this->suffix = $suffix;
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
286 Extensions/TestDox/ResultPrinter.php
@@ -0,0 +1,286 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit |
+// +------------------------------------------------------------------------+
+// | 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: ResultPrinter.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Framework/AssertionFailedError.php';
+require_once 'PHPUnit2/Framework/Test.php';
+require_once 'PHPUnit2/Framework/TestListener.php';
+require_once 'PHPUnit2/Framework/TestSuite.php';
+require_once 'PHPUnit2/Extensions/TestDox/NamePrettifier.php';
+require_once 'PHPUnit2/Util/Printer.php';
+
+/**
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+abstract class PHPUnit2_Extensions_TestDox_ResultPrinter extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener {
+ // {{{ Instance Variables
+
+ /**
+ * @var PHPUnit2_Extensions_TestDox_NamePrettifier
+ * @access protected
+ */
+ protected $prettifier;
+
+ /**
+ * @var string
+ * @access protected
+ */
+ protected $testClass = '';
+
+ /**
+ * @var boolean
+ * @access protected
+ */
+ protected $testFailed = FALSE;
+
+ // }}}
+ // {{{ public function __construct($out = NULL)
+
+ /**
+ * Constructor.
+ *
+ * @param resource $out
+ * @access public
+ */
+ public function __construct($out = NULL) {
+ parent::__construct($out);
+
+ $this->prettifier = new PHPUnit2_Extensions_TestDox_NamePrettifier;
+ $this->startRun();
+ }
+
+ // }}}
+ // {{{ public function __destruct()
+
+ /**
+ * Destructor.
+ *
+ * @access public
+ */
+ public function __destruct() {
+ $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
+ $this->endRun();
+
+ parent::__destruct();
+ }
+
+ // }}}
+ // {{{ public function factory($type, $out)
+
+ /**
+ * Abstract Factory.
+ *
+ * @param string $type
+ * @param resource $out
+ * @access public
+ * @static
+ */
+ public static function factory($type, $out = NULL) {
+ $class = 'PHPUnit2_Extensions_TestDox_ResultPrinter_' . $type;
+
+ if (@require_once('PHPUnit2/Extensions/TestDox/ResultPrinter/' . $type . '.php')) {
+ $object = new $class($out);
+
+ return $object;
+ } else {
+ throw new Exception(
+ sprintf(
+ 'Could not load class %s.',
+ $class
+ )
+ );
+ }
+ }
+
+ // }}}
+ // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
+
+ /**
+ * An error occurred.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param Exception $e
+ * @access public
+ */
+ public function addError(PHPUnit2_Framework_Test $test, Exception $e) {
+ $this->testFailed = TRUE;
+ }
+
+ // }}}
+ // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
+
+ /**
+ * A failure occurred.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param PHPUnit2_Framework_AssertionFailedError $e
+ * @access public
+ */
+ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) {
+ $this->testFailed = TRUE;
+ }
+
+ // }}}
+ // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
+
+ /**
+ * Incomplete test.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @param Exception $e
+ * @access public
+ */
+ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) {
+ $this->testFailed = TRUE;
+ }
+
+ // }}}
+ // {{{ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite)
+
+ /**
+ * A testsuite started.
+ *
+ * @param PHPUnit2_Framework_TestSuite $suite
+ * @access public
+ * @since 2.2.0
+ */
+ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) {
+ }
+
+ // }}}
+ // {{{ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite)
+
+ /**
+ * A testsuite ended.
+ *
+ * @param PHPUnit2_Framework_TestSuite $suite
+ * @access public
+ * @since 2.2.0
+ */
+ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) {
+ }
+
+ // }}}
+ // {{{ public function startTest(PHPUnit2_Framework_Test $test)
+
+ /**
+ * A test started.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ public function startTest(PHPUnit2_Framework_Test $test) {
+ $class = get_class($test);
+
+ if ($this->testClass != $class) {
+ if ($this->testClass != '') {
+ $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
+ }
+
+ $this->startClass($this->prettifier->prettifyTestClass($class));
+ $this->testClass = $class;
+ }
+
+ $this->testFailed = FALSE;
+ }
+
+ // }}}
+ // {{{ public function endTest(PHPUnit2_Framework_Test $test)
+
+ /**
+ * A test ended.
+ *
+ * @param PHPUnit2_Framework_Test $test
+ * @access public
+ */
+ public function endTest(PHPUnit2_Framework_Test $test) {
+ if (!$this->testFailed) {
+ $this->onTest($this->prettifier->prettifyTestMethod($test->getName()));
+ }
+ }
+
+ // }}}
+ // {{{ abstract protected function startClass($name)
+
+ /**
+ * Handler for 'start class' event.
+ *
+ * @param string $name
+ * @access public
+ * @abstract
+ */
+ abstract protected function startClass($name);
+
+ // }}}
+ // {{{ abstract protected function onTest($name)
+
+ /**
+ * Handler for 'on test' event.
+ *
+ * @param string $name
+ * @access public
+ * @abstract
+ */
+ abstract protected function onTest($name);
+
+ // }}}
+ // {{{ abstract protected function endClass($name)
+
+ /**
+ * Handler for 'end class' event.
+ *
+ * @param string $name
+ * @access public
+ * @abstract
+ */
+ abstract protected function endClass($name);
+
+ // }}}
+ // {{{ abstract protected function startRun()
+
+ /**
+ * Handler for 'start run' event.
+ *
+ * @access public
+ * @abstract
+ */
+ abstract protected function startRun();
+
+ // }}}
+ // {{{ abstract protected function endRun()
+
+ /**
+ * Handler for 'end run' event.
+ *
+ * @access public
+ * @abstract
+ */
+ abstract protected function endRun();
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
97 Extensions/TestDox/ResultPrinter/HTML.php
@@ -0,0 +1,97 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit |
+// +------------------------------------------------------------------------+
+// | 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: HTML.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Extensions/TestDox/ResultPrinter.php';
+
+/**
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_TestDox_ResultPrinter_HTML extends PHPUnit2_Extensions_TestDox_ResultPrinter {
+ // {{{ protected function startClass($name)
+
+ /**
+ * Handler for 'start class' event.
+ *
+ * @param string $name
+ * @access protected
+ */
+ protected function startClass($name) {
+ $this->write('<h2>' . $name . '</h2><ul>');
+ }
+
+ // }}}
+ // {{{ protected function onTest($name)
+
+ /**
+ * Handler for 'on test' event.
+ *
+ * @param string $name
+ * @access protected
+ */
+ protected function onTest($name) {
+ $this->write('<li>' . $name . '</li>');
+ }
+
+ // }}}
+ // {{{ protected function endClass($name)
+
+ /**
+ * Handler for 'end class' event.
+ *
+ * @param string $name
+ * @access protected
+ */
+ protected function endClass($name) {
+ $this->write('</ul>');
+ }
+
+ // }}}
+ // {{{ protected function startRun()
+
+ /**
+ * Handler for 'start run' event.
+ *
+ * @access protected
+ */
+ protected function startRun() {
+ }
+
+ // }}}
+ // {{{ protected function endRun()
+
+ /**
+ * Handler for 'end run' event.
+ *
+ * @access protected
+ */
+ protected function endRun() {
+ }
+
+ // }}}
+}
+
+/*
+ * vim600: et sw=2 ts=2 fdm=marker
+ * vim<600: et sw=2 ts=2
+ */
+?>
97 Extensions/TestDox/ResultPrinter/Text.php
@@ -0,0 +1,97 @@
+<?php
+//
+// +------------------------------------------------------------------------+
+// | PEAR :: PHPUnit |
+// +------------------------------------------------------------------------+
+// | 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: Text.php 539 2006-02-13 16:08:42Z sb $
+//
+
+require_once 'PHPUnit2/Extensions/TestDox/ResultPrinter.php';
+
+/**
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
+ * @category Testing
+ * @package PHPUnit2
+ * @subpackage Extensions
+ * @since 2.1.0
+ */
+class PHPUnit2_Extensions_TestDox_ResultPrinter_Text extends PHPUnit2_Extensions_TestDox_ResultPrinter {
+ // {{{ protected function startClass($name)
+
+ /**
+ * Handler for 'start class' event.
+ *
+ * @param string $name
+ * @access protected
+ */
+ protected function startClass($name) {
+ $this->write($name . "\n");