cvs: pear /PHPUnit2 package.xml /PHPUnit2/Extensions/CodeCoverage Renderer.php /PHPUnit2/Extensions/CodeCoverage/Renderer HTML.php Text.php
/PHPUnit2/Extensions/Log PEAR.php XML.php /PHPUnit2/Extensions/TestDox NamePrettifier.php ResultPrinter.php
/PHPUnit2/Extensions/TestDox/ResultPrinter HTML.php Text.php /PHPUnit2/Tests AllTests.php /PHPUnit2/Tests/Extensions AllTests.php
/PHPUnit2/Tests/Extensions/TestDox AllTests.php NamePrettifierTest.php /PHPUnit2/Tests/Util AllTests.php /PHPUnit2/Tests/Util/TestDox AllTests.php
NamePrettifierTest.php /PHPUnit2/TextUI TestRunner.php /PHPUnit2/Util Filter.php /PHPUnit2/Util/CodeCoverage Renderer.php
/PHPUnit2/Util/CodeCoverage/Renderer HTML.php Text.php /PHPUnit2/Util/Log PEAR.php XML.php /PHPUnit2/Util/TestDox NamePrettifier.php
ResultPrinter.php /PHPUnit2/Util/TestDox/ResultPrinter HTML.php Text.php
| From: | Sebastian Bergmann | Date: | Tue, 24 May 2005 09:43:37 +0000 |
| Subject: | cvs: pear /PHPUnit2 package.xml /PHPUnit2/Extensions/CodeCoverage Renderer.php /PHPUnit2/Extensions/CodeCoverage/Renderer HTML.php Text.php /PHPUnit2/Extensions/Log PEAR.php XML.php /PHPUnit2/Extensions/TestDox NamePrettifier.php ResultPrinter.php /PHPUnit2/Extensions/TestDox/ResultPrinter HTML.php Text.php /PHPUnit2/Tests AllTests.php /PHPUnit2/Tests/Extensions AllTests.php /PHPUnit2/Tests/Extensions/TestDox AllTests.php NamePrettifierTest.php /PHPUnit2/Tests/Util AllTests.php /PHPUnit2/Tests/Util/TestDox AllTests.php NamePrettifierTest.php /PHPUnit2/TextUI TestRunner.php /PHPUnit2/Util Filter.php /PHPUnit2/Util/CodeCoverage Renderer.php /PHPUnit2/Util/CodeCoverage/Renderer HTML.php Text.php /PHPUnit2/Util/Log PEAR.php XML.php /PHPUnit2/Util/TestDox NamePrettifier.php ResultPrinter.php /PHPUnit2/Util/TestDox/ResultPrinter HTML.php Text.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-32095@lists.php.net to get a copy of this message | ||
sebastian Tue May 24 05:43:37 2005 EDT
Added files:
/pear/PHPUnit2/Tests/Util AllTests.php
/pear/PHPUnit2/Tests/Util/TestDox AllTests.php
NamePrettifierTest.php
/pear/PHPUnit2/Util/Log PEAR.php XML.php
/pear/PHPUnit2/Util/TestDox NamePrettifier.php ResultPrinter.php
/pear/PHPUnit2/Util/TestDox/ResultPrinter HTML.php Text.php
Removed files:
/pear/PHPUnit2/Extensions/CodeCoverage Renderer.php
/pear/PHPUnit2/Extensions/CodeCoverage/Renderer HTML.php Text.php
/pear/PHPUnit2/Extensions/Log PEAR.php XML.php
/pear/PHPUnit2/Extensions/TestDox NamePrettifier.php
ResultPrinter.php
/pear/PHPUnit2/Extensions/TestDox/ResultPrinter HTML.php Text.php
/pear/PHPUnit2/Tests/Extensions/TestDox AllTests.php
NamePrettifierTest.php
Modified files:
/pear/PHPUnit2 package.xml
/pear/PHPUnit2/Tests AllTests.php
/pear/PHPUnit2/Tests/Extensions AllTests.php
/pear/PHPUnit2/TextUI TestRunner.php
/pear/PHPUnit2/Util Filter.php
/pear/PHPUnit2/Util/CodeCoverage Renderer.php
/pear/PHPUnit2/Util/CodeCoverage/Renderer HTML.php Text.php
Log:
Rename Extensions_CodeCoverage_*, Extensions_Log_*, and Extensions_TestDox_* to
Util_CodeCoverage_*, Util_Log_*, and Util_TestDox_* as the Extensions_* namespace is intended for
extensions of the framework.
http://cvs.php.net/diff.php/pear/PHPUnit2/package.xml?r1=1.108&r2=1.109&ty=u Index: pear/PHPUnit2/package.xml diff -u pear/PHPUnit2/package.xml:1.108 pear/PHPUnit2/package.xml:1.109 --- pear/PHPUnit2/package.xml:1.108 Mon May 23 04:44:18 2005 +++ pear/PHPUnit2/package.xml Tue May 24 05:43:34 2005 @@ -38,6 +38,8 @@ * PHPUnit2 now uses the Standard PHP Library (SPL)'s class loading functionality. +* Renamed Extensions_CodeCoverage_*, Extensions_Log_*, and Extensions_TestDox_* to Util_CodeCoverage_*, Util_Log_*, and Util_TestDox_* as the Extensions_* namespace is intended for extensions of the framework. + * Moved tests outside of installation directory. ! PHP 5.1.0 (or greater) is now required. @@ -48,48 +50,6 @@ <filelist> <dir name="/" baseinstalldir="PHPUnit2"> <dir name="Extensions"> - <dir name="CodeCoverage"> - <dir name="Renderer"> - <file role="php" name="HTML.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="Text.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <file role="php" name="Renderer.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <dir name="Log"> - <file role="php" name="PEAR.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="XML.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <dir name="TestDox"> - <dir name="ResultPrinter"> - <file role="php" name="HTML.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="Text.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <file role="php" name="NamePrettifier.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="ResultPrinter.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - <file role="php" name="ExceptionTestCase.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -225,15 +185,6 @@ </dir> <dir name="Extensions"> - <dir name="TestDox"> - <file name="AllTests.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file name="NamePrettifierTest.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - <file name="AllTests.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -260,6 +211,17 @@ </file> </dir> + <dir name="Util"> + <dir name="TestDox"> + <file name="AllTests.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="NamePrettifierTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + </dir> + <file name="AllTests.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -353,6 +315,48 @@ </dir> <dir name="Util"> + <dir name="CodeCoverage"> + <dir name="Renderer"> + <file role="php" name="HTML.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Text.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <file role="php" name="Renderer.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <dir name="Log"> + <file role="php" name="PEAR.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="XML.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <dir name="TestDox"> + <dir name="ResultPrinter"> + <file role="php" name="HTML.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Text.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <file role="php" name="NamePrettifier.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="ResultPrinter.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + <file role="php" name="Classloader.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> http://cvs.php.net/diff.php/pear/PHPUnit2/Tests/AllTests.php?r1=1.10&r2=1.11&ty=u Index: pear/PHPUnit2/Tests/AllTests.php diff -u pear/PHPUnit2/Tests/AllTests.php:1.10 pear/PHPUnit2/Tests/AllTests.php:1.11 --- pear/PHPUnit2/Tests/AllTests.php:1.10 Mon Apr 11 01:48:09 2005 +++ pear/PHPUnit2/Tests/AllTests.php Tue May 24 05:43:35 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: AllTests.php,v 1.10 2005/04/11 05:48:09 sebastian Exp $ + * @version CVS: $Id: AllTests.php,v 1.11 2005/05/24 09:43:35 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -30,6 +30,7 @@ require_once 'Framework/AllTests.php'; require_once 'Extensions/AllTests.php'; require_once 'Runner/AllTests.php'; +require_once 'Util/AllTests.php'; /** * @@ -54,6 +55,7 @@ $suite->addTest(Framework_AllTests::suite()); $suite->addTest(Extensions_AllTests::suite()); $suite->addTest(Runner_AllTests::suite()); + $suite->addTest(Util_AllTests::suite()); return $suite; } http://cvs.php.net/diff.php/pear/PHPUnit2/Tests/Extensions/AllTests.php?r1=1.11&r2=1.12&ty=u Index: pear/PHPUnit2/Tests/Extensions/AllTests.php diff -u pear/PHPUnit2/Tests/Extensions/AllTests.php:1.11 pear/PHPUnit2/Tests/Extensions/AllTests.php:1.12 --- pear/PHPUnit2/Tests/Extensions/AllTests.php:1.11 Mon Apr 11 01:48:09 2005 +++ pear/PHPUnit2/Tests/Extensions/AllTests.php Tue May 24 05:43:36 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: AllTests.php,v 1.11 2005/04/11 05:48:09 sebastian Exp $ + * @version CVS: $Id: AllTests.php,v 1.12 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -28,7 +28,6 @@ require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'PHPUnit2/Util/Filter.php'; -require_once 'Extensions/TestDox/AllTests.php'; require_once 'Extensions/ExceptionTestCaseTest.php'; require_once 'Extensions/ExtensionTest.php'; require_once 'Extensions/PerformanceTestCaseTest.php'; @@ -54,7 +53,6 @@ public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Extensions'); - $suite->addTest(Extensions_TestDox_AllTests::suite()); $suite->addTestSuite('Extensions_ExceptionTestCaseTest'); $suite->addTestSuite('Extensions_ExtensionTest'); $suite->addTestSuite('Extensions_PerformanceTestCaseTest'); @@ -65,8 +63,6 @@ PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/RepeatedTest.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/TestDecorator.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/TestSetup.php'); - PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/Log/PEAR.php'); - PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/Log/XML.php'); PHPUnit2_Util_Filter::addFileToFilter('Error.php'); PHPUnit2_Util_Filter::addFileToFilter('Failure.php'); http://cvs.php.net/diff.php/pear/PHPUnit2/TextUI/TestRunner.php?r1=1.59&r2=1.60&ty=u Index: pear/PHPUnit2/TextUI/TestRunner.php diff -u pear/PHPUnit2/TextUI/TestRunner.php:1.59 pear/PHPUnit2/TextUI/TestRunner.php:1.60 --- pear/PHPUnit2/TextUI/TestRunner.php:1.59 Mon May 23 04:44:19 2005 +++ pear/PHPUnit2/TextUI/TestRunner.php Tue May 24 05:43:36 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: TestRunner.php,v 1.59 2005/05/23 08:44:19 sebastian Exp $ + * @version CVS: $Id: TestRunner.php,v 1.60 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -356,7 +356,7 @@ if ($testdoxHTMLFile !== FALSE) { $result->addListener( - PHPUnit2_Extensions_TestDox_ResultPrinter::factory( + PHPUnit2_Util_TestDox_ResultPrinter::factory( 'HTML', $testdoxHTMLFile ) @@ -365,7 +365,7 @@ if ($testdoxTextFile !== FALSE) { $result->addListener( - PHPUnit2_Extensions_TestDox_ResultPrinter::factory( + PHPUnit2_Util_TestDox_ResultPrinter::factory( 'Text', $testdoxTextFile ) @@ -374,7 +374,7 @@ if ($xmlLogfile !== FALSE) { $result->addListener( - new PHPUnit2_Extensions_Log_XML($xmlLogfile) + new PHPUnit2_Util_Log_XML($xmlLogfile) ); } @@ -434,7 +434,7 @@ } if ($coverageHTMLFile !== FALSE) { - $renderer = PHPUnit2_Extensions_CodeCoverage_Renderer::factory( + $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory( 'HTML', $result->getCodeCoverageInformation() ); @@ -443,7 +443,7 @@ } if ($coverageTextFile !== FALSE) { - $renderer = PHPUnit2_Extensions_CodeCoverage_Renderer::factory( + $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory( 'Text', $result->getCodeCoverageInformation() ); http://cvs.php.net/diff.php/pear/PHPUnit2/Util/Filter.php?r1=1.28&r2=1.29&ty=u Index: pear/PHPUnit2/Util/Filter.php diff -u pear/PHPUnit2/Util/Filter.php:1.28 pear/PHPUnit2/Util/Filter.php:1.29 --- pear/PHPUnit2/Util/Filter.php:1.28 Mon May 23 00:23:33 2005 +++ pear/PHPUnit2/Util/Filter.php Tue May 24 05:43:36 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Filter.php,v 1.28 2005/05/23 04:23:33 sebastian Exp $ + * @version CVS: $Id: Filter.php,v 1.29 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -41,15 +41,6 @@ * @static */ protected static $filteredFiles = array( - 'PHPUnit2/Extensions/CodeCoverage/Renderer/HTML.php', - 'PHPUnit2/Extensions/CodeCoverage/Renderer/Text.php', - 'PHPUnit2/Extensions/CodeCoverage/Renderer.php', - 'PHPUnit2/Extensions/Log/PEAR.php', - 'PHPUnit2/Extensions/Log/XML.php', - 'PHPUnit2/Extensions/TestDox/ResultPrinter/HTML.php', - 'PHPUnit2/Extensions/TestDox/ResultPrinter/Text.php', - 'PHPUnit2/Extensions/TestDox/NamePrettifier.php', - 'PHPUnit2/Extensions/TestDox/ResultPrinter.php', 'PHPUnit2/Extensions/ExceptionTestCase.php', 'PHPUnit2/Extensions/PerformanceTestCase.php', 'PHPUnit2/Extensions/RepeatedTest.php', @@ -77,6 +68,15 @@ 'PHPUnit2/Runner/Version.php', 'PHPUnit2/TextUI/ResultPrinter.php', 'PHPUnit2/TextUI/TestRunner.php', + 'PHPUnit2/Util/CodeCoverage/Renderer/HTML.php', + 'PHPUnit2/Util/CodeCoverage/Renderer/Text.php', + 'PHPUnit2/Util/CodeCoverage/Renderer.php', + 'PHPUnit2/Util/Log/PEAR.php', + 'PHPUnit2/Util/Log/XML.php', + 'PHPUnit2/Util/TestDox/ResultPrinter/HTML.php', + 'PHPUnit2/Util/TestDox/ResultPrinter/Text.php', + 'PHPUnit2/Util/TestDox/NamePrettifier.php', + 'PHPUnit2/Util/TestDox/ResultPrinter.php', 'PHPUnit2/Util/Classloader.php', 'PHPUnit2/Util/Filter.php', 'PHPUnit2/Util/Printer.php', http://cvs.php.net/diff.php/pear/PHPUnit2/Util/CodeCoverage/Renderer.php?r1=1.6&r2=1.7&ty=u Index: pear/PHPUnit2/Util/CodeCoverage/Renderer.php diff -u /dev/null pear/PHPUnit2/Util/CodeCoverage/Renderer.php:1.7 --- /dev/null Tue May 24 05:43:37 2005 +++ pear/PHPUnit2/Util/CodeCoverage/Renderer.php Tue May 24 05:43:36 2005 @@ -0,0 +1,206 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * PHP Version 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * 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 web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: Renderer.php,v 1.7 2005/05/24 09:43:36 sebastian Exp $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Classloader.php'; + +/** + * Abstract base class for Code Coverage renderers. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + * @abstract + */ +abstract class PHPUnit2_Util_CodeCoverage_Renderer { + /** + * @var array + * @access protected + */ + protected $codeCoverageInformation; + + /** + * @var boolean + * @access protected + */ + protected $useSummary = TRUE; + + /** + * Constructor. + * + * @param array $codeCoverageInformation + * @access protected + */ + protected function __construct($codeCoverageInformation) { + $this->codeCoverageInformation = $codeCoverageInformation; + } + + /** + * Abstract Factory. + * + * @param string $rendererName + * @param array $codeCoverageInformation + * @throws RuntimeException + * @access public + */ + public function factory($rendererName, $codeCoverageInformation) { + $class = 'PHPUnit2_Util_CodeCoverage_Renderer_' . $rendererName; + return new $class($codeCoverageInformation); + } + + /** + * 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(); + } + + /** + * Visualizes the result array of + * PHPUnit2_Framework_TestResult::getCodeCoverageInformation() + * and writes it to a file. + * + * @param string $filename + * @access public + * @since Method available since Release 2.2.0 + */ + public function renderToFile($filename) { + if ($fp = fopen($filename, 'w')) { + fputs( + $fp, + $this->render() + ); + + fclose($fp); + } + } + + /** + * 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 Method available since Release 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; + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function header() { + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function footer() { + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + } + + /** + * @param array $codeLines + * @param array $executedLines + * @return string + * @access protected + * @abstract + */ + abstract protected function renderSourceFile($codeLines, $executedLines); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> http://cvs.php.net/diff.php/pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php?r1=1.5&r2=1.6&ty=u Index: pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php diff -u /dev/null pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php:1.6 --- /dev/null Tue May 24 05:43:37 2005 +++ pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php Tue May 24 05:43:37 2005 @@ -0,0 +1,165 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * PHP Version 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * 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 web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: HTML.php,v 1.6 2005/05/24 09:43:37 sebastian Exp $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Classloader.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> + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_CodeCoverage_Renderer_HTML extends PHPUnit2_Util_CodeCoverage_Renderer { + 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> +'; + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function header() { + return self::pageHeader; + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function footer() { + return self::pageFooter; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + return self::sourceFileHeader; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + return self::sourceFileFooter; + } + + /** + * @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; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> http://cvs.php.net/diff.php/pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php?r1=1.4&r2=1.5&ty=u Index: pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php diff -u /dev/null pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php:1.5 --- /dev/null Tue May 24 05:43:37 2005 +++ pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php Tue May 24 05:43:37 2005 @@ -0,0 +1,99 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * PHP Version 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * 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 web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: Text.php,v 1.5 2005/05/24 09:43:37 sebastian Exp $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Classloader.php'; + +/** + * Renders Code Coverage information in text format. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_CodeCoverage_Renderer_Text extends PHPUnit2_Util_CodeCoverage_Renderer { + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + return ' ' . $sourceFile . "\n\n"; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + return "\n"; + } + + /** + * @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; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> http://cvs.php.net/co.php/pear/PHPUnit2/Tests/Util/AllTests.php?r=1.1&p=1 Index: pear/PHPUnit2/Tests/Util/AllTests.php +++ pear/PHPUnit2/Tests/Util/AllTests.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: AllTests.php,v 1.1 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'Util_AllTests::main'); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'Util/TestDox/AllTests.php'; /** * * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.0.0 */ class Util_AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Utilities'); $suite->addTest(Util_TestDox_AllTests::suite()); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'Util_AllTests::main') { Util_AllTests::main(); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Tests/Util/TestDox/AllTests.php?r=1.1&p=1 Index: pear/PHPUnit2/Tests/Util/TestDox/AllTests.php +++ pear/PHPUnit2/Tests/Util/TestDox/AllTests.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: AllTests.php,v 1.1 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'Util_TestDox_AllTests::main'); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'Util/TestDox/NamePrettifierTest.php'; /** * * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class Util_TestDox_AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit2 TestDox Functionality'); $suite->addTestSuite('Util_TestDox_NamePrettifierTest'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter/HTML.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter/Text.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/NamePrettifier.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter.php'); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'Util_TestDox_AllTests::main') { Extensions_TestDox_AllTests::main(); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Tests/Util/TestDox/NamePrettifierTest.php?r=1.1&p=1 Index: pear/PHPUnit2/Tests/Util/TestDox/NamePrettifierTest.php +++ pear/PHPUnit2/Tests/Util/TestDox/NamePrettifierTest.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: NamePrettifierTest.php,v 1.1 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Framework/TestCase.php'; require_once 'PHPUnit2/Extensions/TestDox/NamePrettifier.php'; /** * * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class Util_TestDox_NamePrettifierTest extends PHPUnit2_Framework_TestCase { private $namePrettifier; protected function setUp() { $this->namePrettifier = new PHPUnit2_Util_TestDox_NamePrettifier; } public function testTitleHasSensibleDefaults() { $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest')); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo')); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest')); } public function testCaterForUserDefinedSuffix() { $this->namePrettifier->setSuffix('TestCase'); $this->namePrettifier->setPrefix(NULL); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTestCase')); $this->assertEquals('TestFoo', $this->namePrettifier->prettifyTestClass('TestFoo')); $this->assertEquals('FooTest', $this->namePrettifier->prettifyTestClass('FooTest')); } public function testCaterForUserDefinedPrefix() { $this->namePrettifier->setSuffix(NULL); $this->namePrettifier->setPrefix('XXX'); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('XXXFoo')); $this->assertEquals('TestXXX', $this->namePrettifier->prettifyTestClass('TestXXX')); $this->assertEquals('XXX', $this->namePrettifier->prettifyTestClass('XXXXXX')); } public function testTestNameIsConvertedToASentence() { $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest')); $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest2')); $this->assertEquals('This2 is a test', $this->namePrettifier->prettifyTestMethod('testThis2IsATest')); $this->assertEquals('database_column_spec is set correctly', $this->namePrettifier->prettifyTestMethod('testdatabase_column_specIsSetCorrectly')); } public function testIsATestIsFalseForNonTestMethods() { $this->assertFalse($this->namePrettifier->isATestMethod('setUp')); $this->assertFalse($this->namePrettifier->isATestMethod('tearDown')); $this->assertFalse($this->namePrettifier->isATestMethod('foo')); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/Log/PEAR.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/Log/PEAR.php +++ pear/PHPUnit2/Util/Log/PEAR.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: PEAR.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; @include_once 'Log.php'; /** * A TestListener that logs to a PEAR_Log sink. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_Log_PEAR implements PHPUnit2_Framework_TestListener { /** * Log. * * @var Log * @access private */ private $log; /** * @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); } /** * 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() ) ); } /** * 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() ) ); } /** * 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() ) ); } /** * A testsuite started. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { $this->log->info( sprintf( 'TestSuite "%s" started.', $suite->getName() ) ); } /** * A testsuite ended. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { $this->log->info( sprintf( 'TestSuite "%s" ended.', $suite->getName() ) ); } /** * 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() ) ); } /** * 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() ) ); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/Log/XML.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/Log/XML.php +++ pear/PHPUnit2/Util/Log/XML.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: XML.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'Benchmark/Timer.php'; require_once 'PHPUnit2/Util/Classloader.php'; /** * A TestListener that generates an XML-based logfile * of the test execution. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_Log_XML extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { /** * @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; /** * 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); } /** * Destructor. * * @access public */ public function __destruct() { if ($this->writeDocument === TRUE) { $this->write($this->getXML()); } parent::__destruct(); } /** * 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]++; } /** * 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]++; } /** * 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]++; } /** * A testsuite started. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 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; } /** * A testsuite ended. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 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--; } /** * 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(); } /** * 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; } /** * Returns the XML as a string. * * @return string * @access public * @since Method available since Release 2.2.0 */ public function getXML() { return $this->document->saveXML(); } /** * 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 Method available since Release 2.2.0 */ public function setWriteDocument($flag) { if (is_bool($flag)) { $this->writeDocument = $flag; } } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/NamePrettifier.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/NamePrettifier.php +++ pear/PHPUnit2/Util/TestDox/NamePrettifier.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: NamePrettifier.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ /** * Prettifies class and method names for use in TestDox documentation. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_TestDox_NamePrettifier { /** * @var string * @access protected */ protected $prefix = 'Test'; /** * @var string * @access protected */ protected $suffix = 'Test'; /** * 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; } /** * 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; } /** * Prettifies the name of a test method. * * @param string $testMethodName * @return string * @access public */ public function prettifyTestMethod($testMethodName) { $buffer = ''; $testMethodName = preg_replace('#\d+$#', '', $testMethodName); 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; } /** * Sets the prefix of test names. * * @param string $prefix * @access public */ public function setPrefix($prefix) { $this->prefix = $prefix; } /** * Sets the suffix of test names. * * @param string $prefix * @access public */ public function setSuffix($suffix) { $this->suffix = $suffix; } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/ResultPrinter.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/ResultPrinter.php +++ pear/PHPUnit2/Util/TestDox/ResultPrinter.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: ResultPrinter.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; /** * Base class for printers of TestDox documentation. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 * @abstract */ abstract class PHPUnit2_Util_TestDox_ResultPrinter extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { /** * @var PHPUnit2_Util_TestDox_NamePrettifier * @access protected */ protected $prettifier; /** * @var string * @access protected */ protected $testClass = ''; /** * @var boolean * @access protected */ protected $testFailed = FALSE; /** * @var array * @access protected */ protected $tests = array(); /** * Constructor. * * @param resource $out * @access public */ public function __construct($out = NULL) { parent::__construct($out); $this->prettifier = new PHPUnit2_Util_TestDox_NamePrettifier; $this->startRun(); } /** * Destructor. * * @access public */ public function __destruct() { $this->doEndClass(); $this->endRun(); parent::__destruct(); } /** * Abstract Factory. * * @param string $type * @param resource $out * @throws RuntimeException * @access public * @static */ public static function factory($type, $out = NULL) { $class = 'PHPUnit2_Util_TestDox_ResultPrinter_' . $type; return new $class($out); } /** * 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; } /** * 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; } /** * Incomplete test. * * @param PHPUnit2_Framework_Test $test * @param Exception $e * @access public */ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { $this->testFailed = TRUE; } /** * A testsuite started. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { } /** * A testsuite ended. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { } /** * 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->doEndClass(); } $this->startClass($this->prettifier->prettifyTestClass($class)); $this->testClass = $class; $this->tests = array(); } $this->testFailed = FALSE; } /** * A test ended. * * @param PHPUnit2_Framework_Test $test * @access public */ public function endTest(PHPUnit2_Framework_Test $test) { $prettifiedName = $this->prettifier->prettifyTestMethod($test->getName()); if (!isset($this->tests[$prettifiedName])) { if (!$this->testFailed) { $this->tests[$prettifiedName]['success'] = 1; $this->tests[$prettifiedName]['failure'] = 0; } else { $this->tests[$prettifiedName]['success'] = 0; $this->tests[$prettifiedName]['failure'] = 1; } } else { if (!$this->testFailed) { $this->tests[$prettifiedName]['success']++; } else { $this->tests[$prettifiedName]['failure']++; } } } /** * @access private * @since Method available since Release 2.3.0 */ private function doEndClass() { foreach ($this->tests as $name => $data) { if ($data['failures'] == 0) { $this->onTest($name); } } $this->endClass($this->prettifier->prettifyTestClass($this->testClass)); } /** * Handler for 'start run' event. * * @access protected */ protected function startRun() { } /** * Handler for 'start class' event. * * @param string $name * @access protected * @abstract */ abstract protected function startClass($name); /** * Handler for 'on test' event. * * @param string $name * @access protected * @abstract */ abstract protected function onTest($name); /** * Handler for 'end class' event. * * @param string $name * @access protected * @abstract */ abstract protected function endClass($name); /** * Handler for 'end run' event. * * @access protected */ protected function endRun() { } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/ResultPrinter/HTML.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/ResultPrinter/HTML.php +++ pear/PHPUnit2/Util/TestDox/ResultPrinter/HTML.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: HTML.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; /** * Prints TestDox documentation in HTML format. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_TestDox_ResultPrinter_HTML extends PHPUnit2_Util_TestDox_ResultPrinter { /** * Handler for 'start run' event. * * @access protected */ protected function startRun() { $this->write('<html><body>'); } /** * Handler for 'start class' event. * * @param string $name * @access protected */ protected function startClass($name) { $this->write('<h2>' . $name . '</h2><ul>'); } /** * Handler for 'on test' event. * * @param string $name * @access protected */ protected function onTest($name) { $this->write('<li>' . $name . '</li>'); } /** * Handler for 'end class' event. * * @param string $name * @access protected */ protected function endClass($name) { $this->write('</ul>'); } /** * Handler for 'end run' event. * * @access protected */ protected function endRun() { $this->write('</body></html>'); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/ResultPrinter/Text.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/ResultPrinter/Text.php +++ pear/PHPUnit2/Util/TestDox/ResultPrinter/Text.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: Text.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; /** * Prints TestDox documentation in text format. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_TestDox_ResultPrinter_Text extends PHPUnit2_Util_TestDox_ResultPrinter { /** * Handler for 'start class' event. * * @param string $name * @access protected */ protected function startClass($name) { $this->write($name . "\n"); } /** * Handler for 'on test' event. * * @param string $name * @access protected */ protected function onTest($name) { $this->write(' - ' . $name . "\n"); } /** * Handler for 'end class' event. * * @param string $name * @access protected */ protected function endClass($name) { $this->write("\n"); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?>
http://cvs.php.net/diff.php/pear/PHPUnit2/package.xml?r1=1.108&r2=1.109&ty=u Index: pear/PHPUnit2/package.xml diff -u pear/PHPUnit2/package.xml:1.108 pear/PHPUnit2/package.xml:1.109 --- pear/PHPUnit2/package.xml:1.108 Mon May 23 04:44:18 2005 +++ pear/PHPUnit2/package.xml Tue May 24 05:43:34 2005 @@ -38,6 +38,8 @@ * PHPUnit2 now uses the Standard PHP Library (SPL)'s class loading functionality. +* Renamed Extensions_CodeCoverage_*, Extensions_Log_*, and Extensions_TestDox_* to Util_CodeCoverage_*, Util_Log_*, and Util_TestDox_* as the Extensions_* namespace is intended for extensions of the framework. + * Moved tests outside of installation directory. ! PHP 5.1.0 (or greater) is now required. @@ -48,48 +50,6 @@ <filelist> <dir name="/" baseinstalldir="PHPUnit2"> <dir name="Extensions"> - <dir name="CodeCoverage"> - <dir name="Renderer"> - <file role="php" name="HTML.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="Text.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <file role="php" name="Renderer.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <dir name="Log"> - <file role="php" name="PEAR.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="XML.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <dir name="TestDox"> - <dir name="ResultPrinter"> - <file role="php" name="HTML.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="Text.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - - <file role="php" name="NamePrettifier.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file role="php" name="ResultPrinter.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - <file role="php" name="ExceptionTestCase.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -225,15 +185,6 @@ </dir> <dir name="Extensions"> - <dir name="TestDox"> - <file name="AllTests.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - <file name="NamePrettifierTest.php"> - <replace type="package-info" from="@package_version@" to="version"/> - </file> - </dir> - <file name="AllTests.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -260,6 +211,17 @@ </file> </dir> + <dir name="Util"> + <dir name="TestDox"> + <file name="AllTests.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file name="NamePrettifierTest.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + </dir> + <file name="AllTests.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -353,6 +315,48 @@ </dir> <dir name="Util"> + <dir name="CodeCoverage"> + <dir name="Renderer"> + <file role="php" name="HTML.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Text.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <file role="php" name="Renderer.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <dir name="Log"> + <file role="php" name="PEAR.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="XML.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <dir name="TestDox"> + <dir name="ResultPrinter"> + <file role="php" name="HTML.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Text.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + + <file role="php" name="NamePrettifier.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="ResultPrinter.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> + <file role="php" name="Classloader.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> http://cvs.php.net/diff.php/pear/PHPUnit2/Tests/AllTests.php?r1=1.10&r2=1.11&ty=u Index: pear/PHPUnit2/Tests/AllTests.php diff -u pear/PHPUnit2/Tests/AllTests.php:1.10 pear/PHPUnit2/Tests/AllTests.php:1.11 --- pear/PHPUnit2/Tests/AllTests.php:1.10 Mon Apr 11 01:48:09 2005 +++ pear/PHPUnit2/Tests/AllTests.php Tue May 24 05:43:35 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: AllTests.php,v 1.10 2005/04/11 05:48:09 sebastian Exp $ + * @version CVS: $Id: AllTests.php,v 1.11 2005/05/24 09:43:35 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -30,6 +30,7 @@ require_once 'Framework/AllTests.php'; require_once 'Extensions/AllTests.php'; require_once 'Runner/AllTests.php'; +require_once 'Util/AllTests.php'; /** * @@ -54,6 +55,7 @@ $suite->addTest(Framework_AllTests::suite()); $suite->addTest(Extensions_AllTests::suite()); $suite->addTest(Runner_AllTests::suite()); + $suite->addTest(Util_AllTests::suite()); return $suite; } http://cvs.php.net/diff.php/pear/PHPUnit2/Tests/Extensions/AllTests.php?r1=1.11&r2=1.12&ty=u Index: pear/PHPUnit2/Tests/Extensions/AllTests.php diff -u pear/PHPUnit2/Tests/Extensions/AllTests.php:1.11 pear/PHPUnit2/Tests/Extensions/AllTests.php:1.12 --- pear/PHPUnit2/Tests/Extensions/AllTests.php:1.11 Mon Apr 11 01:48:09 2005 +++ pear/PHPUnit2/Tests/Extensions/AllTests.php Tue May 24 05:43:36 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: AllTests.php,v 1.11 2005/04/11 05:48:09 sebastian Exp $ + * @version CVS: $Id: AllTests.php,v 1.12 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -28,7 +28,6 @@ require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'PHPUnit2/Util/Filter.php'; -require_once 'Extensions/TestDox/AllTests.php'; require_once 'Extensions/ExceptionTestCaseTest.php'; require_once 'Extensions/ExtensionTest.php'; require_once 'Extensions/PerformanceTestCaseTest.php'; @@ -54,7 +53,6 @@ public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Extensions'); - $suite->addTest(Extensions_TestDox_AllTests::suite()); $suite->addTestSuite('Extensions_ExceptionTestCaseTest'); $suite->addTestSuite('Extensions_ExtensionTest'); $suite->addTestSuite('Extensions_PerformanceTestCaseTest'); @@ -65,8 +63,6 @@ PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/RepeatedTest.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/TestDecorator.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/TestSetup.php'); - PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/Log/PEAR.php'); - PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/Log/XML.php'); PHPUnit2_Util_Filter::addFileToFilter('Error.php'); PHPUnit2_Util_Filter::addFileToFilter('Failure.php'); http://cvs.php.net/diff.php/pear/PHPUnit2/TextUI/TestRunner.php?r1=1.59&r2=1.60&ty=u Index: pear/PHPUnit2/TextUI/TestRunner.php diff -u pear/PHPUnit2/TextUI/TestRunner.php:1.59 pear/PHPUnit2/TextUI/TestRunner.php:1.60 --- pear/PHPUnit2/TextUI/TestRunner.php:1.59 Mon May 23 04:44:19 2005 +++ pear/PHPUnit2/TextUI/TestRunner.php Tue May 24 05:43:36 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: TestRunner.php,v 1.59 2005/05/23 08:44:19 sebastian Exp $ + * @version CVS: $Id: TestRunner.php,v 1.60 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -356,7 +356,7 @@ if ($testdoxHTMLFile !== FALSE) { $result->addListener( - PHPUnit2_Extensions_TestDox_ResultPrinter::factory( + PHPUnit2_Util_TestDox_ResultPrinter::factory( 'HTML', $testdoxHTMLFile ) @@ -365,7 +365,7 @@ if ($testdoxTextFile !== FALSE) { $result->addListener( - PHPUnit2_Extensions_TestDox_ResultPrinter::factory( + PHPUnit2_Util_TestDox_ResultPrinter::factory( 'Text', $testdoxTextFile ) @@ -374,7 +374,7 @@ if ($xmlLogfile !== FALSE) { $result->addListener( - new PHPUnit2_Extensions_Log_XML($xmlLogfile) + new PHPUnit2_Util_Log_XML($xmlLogfile) ); } @@ -434,7 +434,7 @@ } if ($coverageHTMLFile !== FALSE) { - $renderer = PHPUnit2_Extensions_CodeCoverage_Renderer::factory( + $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory( 'HTML', $result->getCodeCoverageInformation() ); @@ -443,7 +443,7 @@ } if ($coverageTextFile !== FALSE) { - $renderer = PHPUnit2_Extensions_CodeCoverage_Renderer::factory( + $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory( 'Text', $result->getCodeCoverageInformation() ); http://cvs.php.net/diff.php/pear/PHPUnit2/Util/Filter.php?r1=1.28&r2=1.29&ty=u Index: pear/PHPUnit2/Util/Filter.php diff -u pear/PHPUnit2/Util/Filter.php:1.28 pear/PHPUnit2/Util/Filter.php:1.29 --- pear/PHPUnit2/Util/Filter.php:1.28 Mon May 23 00:23:33 2005 +++ pear/PHPUnit2/Util/Filter.php Tue May 24 05:43:36 2005 @@ -15,7 +15,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Filter.php,v 1.28 2005/05/23 04:23:33 sebastian Exp $ + * @version CVS: $Id: Filter.php,v 1.29 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -41,15 +41,6 @@ * @static */ protected static $filteredFiles = array( - 'PHPUnit2/Extensions/CodeCoverage/Renderer/HTML.php', - 'PHPUnit2/Extensions/CodeCoverage/Renderer/Text.php', - 'PHPUnit2/Extensions/CodeCoverage/Renderer.php', - 'PHPUnit2/Extensions/Log/PEAR.php', - 'PHPUnit2/Extensions/Log/XML.php', - 'PHPUnit2/Extensions/TestDox/ResultPrinter/HTML.php', - 'PHPUnit2/Extensions/TestDox/ResultPrinter/Text.php', - 'PHPUnit2/Extensions/TestDox/NamePrettifier.php', - 'PHPUnit2/Extensions/TestDox/ResultPrinter.php', 'PHPUnit2/Extensions/ExceptionTestCase.php', 'PHPUnit2/Extensions/PerformanceTestCase.php', 'PHPUnit2/Extensions/RepeatedTest.php', @@ -77,6 +68,15 @@ 'PHPUnit2/Runner/Version.php', 'PHPUnit2/TextUI/ResultPrinter.php', 'PHPUnit2/TextUI/TestRunner.php', + 'PHPUnit2/Util/CodeCoverage/Renderer/HTML.php', + 'PHPUnit2/Util/CodeCoverage/Renderer/Text.php', + 'PHPUnit2/Util/CodeCoverage/Renderer.php', + 'PHPUnit2/Util/Log/PEAR.php', + 'PHPUnit2/Util/Log/XML.php', + 'PHPUnit2/Util/TestDox/ResultPrinter/HTML.php', + 'PHPUnit2/Util/TestDox/ResultPrinter/Text.php', + 'PHPUnit2/Util/TestDox/NamePrettifier.php', + 'PHPUnit2/Util/TestDox/ResultPrinter.php', 'PHPUnit2/Util/Classloader.php', 'PHPUnit2/Util/Filter.php', 'PHPUnit2/Util/Printer.php', http://cvs.php.net/diff.php/pear/PHPUnit2/Util/CodeCoverage/Renderer.php?r1=1.6&r2=1.7&ty=u Index: pear/PHPUnit2/Util/CodeCoverage/Renderer.php diff -u /dev/null pear/PHPUnit2/Util/CodeCoverage/Renderer.php:1.7 --- /dev/null Tue May 24 05:43:37 2005 +++ pear/PHPUnit2/Util/CodeCoverage/Renderer.php Tue May 24 05:43:36 2005 @@ -0,0 +1,206 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * PHP Version 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * 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 web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: Renderer.php,v 1.7 2005/05/24 09:43:36 sebastian Exp $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Classloader.php'; + +/** + * Abstract base class for Code Coverage renderers. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + * @abstract + */ +abstract class PHPUnit2_Util_CodeCoverage_Renderer { + /** + * @var array + * @access protected + */ + protected $codeCoverageInformation; + + /** + * @var boolean + * @access protected + */ + protected $useSummary = TRUE; + + /** + * Constructor. + * + * @param array $codeCoverageInformation + * @access protected + */ + protected function __construct($codeCoverageInformation) { + $this->codeCoverageInformation = $codeCoverageInformation; + } + + /** + * Abstract Factory. + * + * @param string $rendererName + * @param array $codeCoverageInformation + * @throws RuntimeException + * @access public + */ + public function factory($rendererName, $codeCoverageInformation) { + $class = 'PHPUnit2_Util_CodeCoverage_Renderer_' . $rendererName; + return new $class($codeCoverageInformation); + } + + /** + * 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(); + } + + /** + * Visualizes the result array of + * PHPUnit2_Framework_TestResult::getCodeCoverageInformation() + * and writes it to a file. + * + * @param string $filename + * @access public + * @since Method available since Release 2.2.0 + */ + public function renderToFile($filename) { + if ($fp = fopen($filename, 'w')) { + fputs( + $fp, + $this->render() + ); + + fclose($fp); + } + } + + /** + * 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 Method available since Release 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; + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function header() { + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function footer() { + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + } + + /** + * @param array $codeLines + * @param array $executedLines + * @return string + * @access protected + * @abstract + */ + abstract protected function renderSourceFile($codeLines, $executedLines); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> http://cvs.php.net/diff.php/pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php?r1=1.5&r2=1.6&ty=u Index: pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php diff -u /dev/null pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php:1.6 --- /dev/null Tue May 24 05:43:37 2005 +++ pear/PHPUnit2/Util/CodeCoverage/Renderer/HTML.php Tue May 24 05:43:37 2005 @@ -0,0 +1,165 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * PHP Version 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * 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 web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: HTML.php,v 1.6 2005/05/24 09:43:37 sebastian Exp $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Classloader.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> + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_CodeCoverage_Renderer_HTML extends PHPUnit2_Util_CodeCoverage_Renderer { + 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> +'; + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function header() { + return self::pageHeader; + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function footer() { + return self::pageFooter; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + return self::sourceFileHeader; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + return self::sourceFileFooter; + } + + /** + * @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; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> http://cvs.php.net/diff.php/pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php?r1=1.4&r2=1.5&ty=u Index: pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php diff -u /dev/null pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php:1.5 --- /dev/null Tue May 24 05:43:37 2005 +++ pear/PHPUnit2/Util/CodeCoverage/Renderer/Text.php Tue May 24 05:43:37 2005 @@ -0,0 +1,99 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * PHP Version 5 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * 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 web, please + * send a note to license@php.net so we can mail you a copy immediately. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version CVS: $Id: Text.php,v 1.5 2005/05/24 09:43:37 sebastian Exp $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Classloader.php'; + +/** + * Renders Code Coverage information in text format. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> + * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_CodeCoverage_Renderer_Text extends PHPUnit2_Util_CodeCoverage_Renderer { + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + return ' ' . $sourceFile . "\n\n"; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + return "\n"; + } + + /** + * @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; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> http://cvs.php.net/co.php/pear/PHPUnit2/Tests/Util/AllTests.php?r=1.1&p=1 Index: pear/PHPUnit2/Tests/Util/AllTests.php +++ pear/PHPUnit2/Tests/Util/AllTests.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: AllTests.php,v 1.1 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'Util_AllTests::main'); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'Util/TestDox/AllTests.php'; /** * * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.0.0 */ class Util_AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Utilities'); $suite->addTest(Util_TestDox_AllTests::suite()); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'Util_AllTests::main') { Util_AllTests::main(); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Tests/Util/TestDox/AllTests.php?r=1.1&p=1 Index: pear/PHPUnit2/Tests/Util/TestDox/AllTests.php +++ pear/PHPUnit2/Tests/Util/TestDox/AllTests.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: AllTests.php,v 1.1 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'Util_TestDox_AllTests::main'); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once 'Util/TestDox/NamePrettifierTest.php'; /** * * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class Util_TestDox_AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('PHPUnit2 TestDox Functionality'); $suite->addTestSuite('Util_TestDox_NamePrettifierTest'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter/HTML.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter/Text.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/NamePrettifier.php'); PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter.php'); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'Util_TestDox_AllTests::main') { Extensions_TestDox_AllTests::main(); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Tests/Util/TestDox/NamePrettifierTest.php?r=1.1&p=1 Index: pear/PHPUnit2/Tests/Util/TestDox/NamePrettifierTest.php +++ pear/PHPUnit2/Tests/Util/TestDox/NamePrettifierTest.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: NamePrettifierTest.php,v 1.1 2005/05/24 09:43:36 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Framework/TestCase.php'; require_once 'PHPUnit2/Extensions/TestDox/NamePrettifier.php'; /** * * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class Util_TestDox_NamePrettifierTest extends PHPUnit2_Framework_TestCase { private $namePrettifier; protected function setUp() { $this->namePrettifier = new PHPUnit2_Util_TestDox_NamePrettifier; } public function testTitleHasSensibleDefaults() { $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest')); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo')); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest')); } public function testCaterForUserDefinedSuffix() { $this->namePrettifier->setSuffix('TestCase'); $this->namePrettifier->setPrefix(NULL); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTestCase')); $this->assertEquals('TestFoo', $this->namePrettifier->prettifyTestClass('TestFoo')); $this->assertEquals('FooTest', $this->namePrettifier->prettifyTestClass('FooTest')); } public function testCaterForUserDefinedPrefix() { $this->namePrettifier->setSuffix(NULL); $this->namePrettifier->setPrefix('XXX'); $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('XXXFoo')); $this->assertEquals('TestXXX', $this->namePrettifier->prettifyTestClass('TestXXX')); $this->assertEquals('XXX', $this->namePrettifier->prettifyTestClass('XXXXXX')); } public function testTestNameIsConvertedToASentence() { $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest')); $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest2')); $this->assertEquals('This2 is a test', $this->namePrettifier->prettifyTestMethod('testThis2IsATest')); $this->assertEquals('database_column_spec is set correctly', $this->namePrettifier->prettifyTestMethod('testdatabase_column_specIsSetCorrectly')); } public function testIsATestIsFalseForNonTestMethods() { $this->assertFalse($this->namePrettifier->isATestMethod('setUp')); $this->assertFalse($this->namePrettifier->isATestMethod('tearDown')); $this->assertFalse($this->namePrettifier->isATestMethod('foo')); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/Log/PEAR.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/Log/PEAR.php +++ pear/PHPUnit2/Util/Log/PEAR.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: PEAR.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; @include_once 'Log.php'; /** * A TestListener that logs to a PEAR_Log sink. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_Log_PEAR implements PHPUnit2_Framework_TestListener { /** * Log. * * @var Log * @access private */ private $log; /** * @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); } /** * 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() ) ); } /** * 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() ) ); } /** * 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() ) ); } /** * A testsuite started. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { $this->log->info( sprintf( 'TestSuite "%s" started.', $suite->getName() ) ); } /** * A testsuite ended. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { $this->log->info( sprintf( 'TestSuite "%s" ended.', $suite->getName() ) ); } /** * 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() ) ); } /** * 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() ) ); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/Log/XML.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/Log/XML.php +++ pear/PHPUnit2/Util/Log/XML.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: XML.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'Benchmark/Timer.php'; require_once 'PHPUnit2/Util/Classloader.php'; /** * A TestListener that generates an XML-based logfile * of the test execution. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_Log_XML extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { /** * @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; /** * 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); } /** * Destructor. * * @access public */ public function __destruct() { if ($this->writeDocument === TRUE) { $this->write($this->getXML()); } parent::__destruct(); } /** * 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]++; } /** * 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]++; } /** * 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]++; } /** * A testsuite started. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 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; } /** * A testsuite ended. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 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--; } /** * 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(); } /** * 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; } /** * Returns the XML as a string. * * @return string * @access public * @since Method available since Release 2.2.0 */ public function getXML() { return $this->document->saveXML(); } /** * 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 Method available since Release 2.2.0 */ public function setWriteDocument($flag) { if (is_bool($flag)) { $this->writeDocument = $flag; } } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/NamePrettifier.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/NamePrettifier.php +++ pear/PHPUnit2/Util/TestDox/NamePrettifier.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: NamePrettifier.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ /** * Prettifies class and method names for use in TestDox documentation. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_TestDox_NamePrettifier { /** * @var string * @access protected */ protected $prefix = 'Test'; /** * @var string * @access protected */ protected $suffix = 'Test'; /** * 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; } /** * 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; } /** * Prettifies the name of a test method. * * @param string $testMethodName * @return string * @access public */ public function prettifyTestMethod($testMethodName) { $buffer = ''; $testMethodName = preg_replace('#\d+$#', '', $testMethodName); 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; } /** * Sets the prefix of test names. * * @param string $prefix * @access public */ public function setPrefix($prefix) { $this->prefix = $prefix; } /** * Sets the suffix of test names. * * @param string $prefix * @access public */ public function setSuffix($suffix) { $this->suffix = $suffix; } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/ResultPrinter.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/ResultPrinter.php +++ pear/PHPUnit2/Util/TestDox/ResultPrinter.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: ResultPrinter.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; /** * Base class for printers of TestDox documentation. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 * @abstract */ abstract class PHPUnit2_Util_TestDox_ResultPrinter extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { /** * @var PHPUnit2_Util_TestDox_NamePrettifier * @access protected */ protected $prettifier; /** * @var string * @access protected */ protected $testClass = ''; /** * @var boolean * @access protected */ protected $testFailed = FALSE; /** * @var array * @access protected */ protected $tests = array(); /** * Constructor. * * @param resource $out * @access public */ public function __construct($out = NULL) { parent::__construct($out); $this->prettifier = new PHPUnit2_Util_TestDox_NamePrettifier; $this->startRun(); } /** * Destructor. * * @access public */ public function __destruct() { $this->doEndClass(); $this->endRun(); parent::__destruct(); } /** * Abstract Factory. * * @param string $type * @param resource $out * @throws RuntimeException * @access public * @static */ public static function factory($type, $out = NULL) { $class = 'PHPUnit2_Util_TestDox_ResultPrinter_' . $type; return new $class($out); } /** * 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; } /** * 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; } /** * Incomplete test. * * @param PHPUnit2_Framework_Test $test * @param Exception $e * @access public */ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { $this->testFailed = TRUE; } /** * A testsuite started. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { } /** * A testsuite ended. * * @param PHPUnit2_Framework_TestSuite $suite * @access public * @since Method available since Release 2.2.0 */ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { } /** * 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->doEndClass(); } $this->startClass($this->prettifier->prettifyTestClass($class)); $this->testClass = $class; $this->tests = array(); } $this->testFailed = FALSE; } /** * A test ended. * * @param PHPUnit2_Framework_Test $test * @access public */ public function endTest(PHPUnit2_Framework_Test $test) { $prettifiedName = $this->prettifier->prettifyTestMethod($test->getName()); if (!isset($this->tests[$prettifiedName])) { if (!$this->testFailed) { $this->tests[$prettifiedName]['success'] = 1; $this->tests[$prettifiedName]['failure'] = 0; } else { $this->tests[$prettifiedName]['success'] = 0; $this->tests[$prettifiedName]['failure'] = 1; } } else { if (!$this->testFailed) { $this->tests[$prettifiedName]['success']++; } else { $this->tests[$prettifiedName]['failure']++; } } } /** * @access private * @since Method available since Release 2.3.0 */ private function doEndClass() { foreach ($this->tests as $name => $data) { if ($data['failures'] == 0) { $this->onTest($name); } } $this->endClass($this->prettifier->prettifyTestClass($this->testClass)); } /** * Handler for 'start run' event. * * @access protected */ protected function startRun() { } /** * Handler for 'start class' event. * * @param string $name * @access protected * @abstract */ abstract protected function startClass($name); /** * Handler for 'on test' event. * * @param string $name * @access protected * @abstract */ abstract protected function onTest($name); /** * Handler for 'end class' event. * * @param string $name * @access protected * @abstract */ abstract protected function endClass($name); /** * Handler for 'end run' event. * * @access protected */ protected function endRun() { } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/ResultPrinter/HTML.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/ResultPrinter/HTML.php +++ pear/PHPUnit2/Util/TestDox/ResultPrinter/HTML.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: HTML.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; /** * Prints TestDox documentation in HTML format. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_TestDox_ResultPrinter_HTML extends PHPUnit2_Util_TestDox_ResultPrinter { /** * Handler for 'start run' event. * * @access protected */ protected function startRun() { $this->write('<html><body>'); } /** * Handler for 'start class' event. * * @param string $name * @access protected */ protected function startClass($name) { $this->write('<h2>' . $name . '</h2><ul>'); } /** * Handler for 'on test' event. * * @param string $name * @access protected */ protected function onTest($name) { $this->write('<li>' . $name . '</li>'); } /** * Handler for 'end class' event. * * @param string $name * @access protected */ protected function endClass($name) { $this->write('</ul>'); } /** * Handler for 'end run' event. * * @access protected */ protected function endRun() { $this->write('</body></html>'); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?> http://cvs.php.net/co.php/pear/PHPUnit2/Util/TestDox/ResultPrinter/Text.php?r=1.1&p=1 Index: pear/PHPUnit2/Util/TestDox/ResultPrinter/Text.php +++ pear/PHPUnit2/Util/TestDox/ResultPrinter/Text.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHP Version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * 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 web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: Text.php,v 1.1 2005/05/24 09:43:37 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.3.0 */ require_once 'PHPUnit2/Util/Classloader.php'; /** * Prints TestDox documentation in text format. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 2.1.0 */ class PHPUnit2_Util_TestDox_ResultPrinter_Text extends PHPUnit2_Util_TestDox_ResultPrinter { /** * Handler for 'start class' event. * * @param string $name * @access protected */ protected function startClass($name) { $this->write($name . "\n"); } /** * Handler for 'on test' event. * * @param string $name * @access protected */ protected function onTest($name) { $this->write(' - ' . $name . "\n"); } /** * Handler for 'end class' event. * * @param string $name * @access protected */ protected function endClass($name) { $this->write("\n"); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?>