cvs: pear /PHPUnit2 package.xml /PHPUnit2/TextUI TestRunner.php /PHPUnit2/Util/Log Eclipse.php

From: Date: Thu, 16 Mar 2006 07:47:32 +0000
Subject: cvs: pear /PHPUnit2 package.xml /PHPUnit2/TextUI TestRunner.php /PHPUnit2/Util/Log Eclipse.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-39118@lists.php.net to get a copy of this message
sebastian Thu Mar 16 07:47:32 2006 UTC Added files: /pear/PHPUnit2/Util/Log Eclipse.php Modified files: /pear/PHPUnit2/TextUI TestRunner.php /pear/PHPUnit2 package.xml Log: Initial commit of a TestListener that talks via a socket connection to Eclipse. Contributed by Steven Balthazor.

http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/TextUI/TestRunner.php?r1=1.90&r2=1.91&diff_format=u Index: pear/PHPUnit2/TextUI/TestRunner.php diff -u pear/PHPUnit2/TextUI/TestRunner.php:1.90 pear/PHPUnit2/TextUI/TestRunner.php:1.91 --- pear/PHPUnit2/TextUI/TestRunner.php:1.90 Thu Mar 9 10:39:46 2006 +++ pear/PHPUnit2/TextUI/TestRunner.php Thu Mar 16 07:47:32 2006 @@ -41,7 +41,7 @@ * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @version CVS: $Id: TestRunner.php,v 1.90 2006/03/09 10:39:46 sebastian Exp $ + * @version CVS: $Id: TestRunner.php,v 1.91 2006/03/16 07:47:32 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -69,6 +69,7 @@ 'PHPUnit2_Util_Report', 'PHPUnit2_Util_Timer', 'PHPUnit2_Util_Skeleton', + 'PHPUnit2_Util_Log_Eclipse', 'PHPUnit2_Util_Log_GraphViz', 'PHPUnit2_Util_Log_TAP', 'PHPUnit2_Util_Log_XML', @@ -152,6 +153,7 @@ $testdoxHTMLFile = FALSE; $testdoxTextFile = FALSE; $graphvizDirectory = FALSE; + $eclipseLogfile = FALSE; $tapLogfile = FALSE; $xmlLogfile = FALSE; $wait = FALSE; @@ -159,6 +161,7 @@ $possibleOptions = array( 'help', 'loader=', + 'log-eclipse=', 'log-tap=', 'log-xml=', 'no-syntax-check', @@ -226,6 +229,11 @@ } break; + case '--log-eclipse': { + $eclipseLogfile = $option[1]; + } + break; + case '--log-graphviz': { $graphvizDirectory = $option[1]; } @@ -319,6 +327,7 @@ $testdoxHTMLFile, $testdoxTextFile, $graphvizDirectory, + $eclipseLogfile, $tapLogfile, $xmlLogfile, $wait @@ -338,13 +347,14 @@ * @param mixed $testdoxHTMLFile * @param mixed $testdoxTextFile * @param mixed $graphvizDirectory + * @param mixed $eclipseLogfile * @param mixed $tapLogfile * @param mixed $xmlLogfile * @param boolean $wait * @access public * @static */ - public static function run($test, $reportDirectory = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizDirectory = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) + public static function run($test, $reportDirectory = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizDirectory = FALSE, $eclipseLogfile = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) { if ($test instanceof ReflectionClass) { $test = new PHPUnit2_Framework_TestSuite($test); @@ -359,6 +369,7 @@ $testdoxHTMLFile, $testdoxTextFile, $graphvizDirectory, + $eclipseLogfile, $tapLogfile, $xmlLogfile, $wait @@ -404,13 +415,14 @@ * @param mixed $testdoxHTMLFile * @param mixed $testdoxTextFile * @param mixed $graphvizDirectory + * @param mixed $eclipseLogfile * @param mixed $tapLogfile * @param mixed $xmlLogfile * @param boolean $wait * @return PHPUnit2_Framework_TestResult * @access public */ - public function doRun(PHPUnit2_Framework_Test $suite, $reportDirectory = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizDirectory = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) + public function doRun(PHPUnit2_Framework_Test $suite, $reportDirectory = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizDirectory = FALSE, $eclipseLogfile = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) { if ($graphvizDirectory !== FALSE) { $graphvizDirectory = $this->getDirectory($graphvizDirectory); @@ -466,6 +478,12 @@ $result->collectCodeCoverageInformation(TRUE); } + if ($eclipseLogfile !== FALSE) { + $result->addListener( + new PHPUnit2_Util_Log_Eclipse($eclipseLogfile) + ); + } + if ($tapLogfile !== FALSE) { $result->addListener( new PHPUnit2_Util_Log_TAP($tapLogfile) http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/package.xml?r1=1.183&r2=1.184&diff_format=u Index: pear/PHPUnit2/package.xml diff -u pear/PHPUnit2/package.xml:1.183 pear/PHPUnit2/package.xml:1.184 --- pear/PHPUnit2/package.xml:1.183 Thu Mar 9 10:39:13 2006 +++ pear/PHPUnit2/package.xml Thu Mar 16 07:47:32 2006 @@ -41,6 +41,8 @@ + Added PHPUnit2_Framework_Assert::getNonPublicProperty() method to read non-public properties from objects. ++ Added a TestListener that talks via a socket connection to Eclipse, developed by Steven Balthazor. + + Added a TestListener that generates a map of the executed tests in GraphViz markup. + Added a TestListener that generates a logfile of the test execution using the Test Anything Protocol (TAP). @@ -537,6 +539,9 @@ <dir name="Util" role="php"> <dir name="Log"> + <file name="Eclipse.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file name="GraphViz.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/Util/Log/Eclipse.php?view=markup&rev=1.1 Index: pear/PHPUnit2/Util/Log/Eclipse.php +++ pear/PHPUnit2/Util/Log/Eclipse.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * PHPUnit * * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @category Testing * @package PHPUnit2 * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version CVS: $Id: Eclipse.php,v 1.1 2006/03/16 07:47:32 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 3.0.0 */ require_once 'PHPUnit2/Util/Classloader.php'; require_once 'PHPUnit2/Util/Filter.php'; PHPUnit2_Util_Classloader::import( array( 'PHPUnit2_Framework_AssertionFailedError', 'PHPUnit2_Framework_Test', 'PHPUnit2_Framework_TestListener', 'PHPUnit2_Framework_TestSuite', 'PHPUnit2_Util_Printer', 'PHPUnit2_Util_Timer', ) ); PHPUnit2_Util_Filter::addFileToFilter(__FILE__); /** * A TestListener that passes a log of the test execution as a JSON string * to Eclipse via a socket connection. * * @category Testing * @package PHPUnit2 * @author Steven Balthazor <stevenbalthazor@gmail.com> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: @package_version@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 3.0.0 */ class PHPUnit2_Util_Log_Eclipse extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { /** * @var String * @access private */ private $currentTestSuiteName = ''; /** * @var String * @access private */ private $currentTestCaseName = ''; /** * @var String * @access private */ private $currentTestMethodName = ''; /** * @var boolean * @access private */ private $currentTestCasePass = TRUE; /** * Constructor. * * @param mixed $out * @access public */ public function __construct($out = NULL) { $this->out = @fsockopen('127.0.0.1', $out, $errnum, $error, 10); if (!$this->out){ throw new RuntimeException( sprintf( 'Error opening socket %s : %s (%s)', $out, $error, $errnum ) ); } } /** * @param string $buffer * @access public */ public function write($buffer) { if ($this->out !== NULL) { fwrite($this->out, $buffer); } } /** * @param string $status * @param string $message * @access private */ private function writeCase($status, $message = '') { $this->write( sprintf( '{status:"%s",message:"%s",group:"%s",case:"%s",method:"%s"}', $status, $this->escapeValue($message), $this->currentTestSuiteName, $this->currentTestCaseName, $this->currentTestMethodName ) ); } /** * @param string $value * @return string * @access private */ private function escapeValue($value) { return str_replace( array("\\","\"","/","\b","\f","\n","\r","\t"), array('\\\\','\"','\/','\b','\f','\n','\r','\t'), $value ); } /** * @param Exception $e * @return String * @access private */ private function getFileLine(Exception $e) { $file = ''; $line = ''; foreach ($e->getTrace() as $frame) { if (!isset($frame['line'])) { break; } $file = $frame['file']; $line = $frame['line']; } return sprintf( ' [%s line %s]', $file, $line ); } /** * An error occurred. * * @param PHPUnit2_Framework_Test $test * @param Exception $e * @access public */ public function addError(PHPUnit2_Framework_Test $test, Exception $e) { $this->writeCase('error', get_class($e) . ':' . $e->getMessage()); $this->currentTestCasePass = FALSE; } /** * 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->writeCase('fail', $e->getMessage() . $this->getFileLine($e)); $this->currentTestCasePass = FALSE; } /** * Incomplete test. * * @param PHPUnit2_Framework_Test $test * @param Exception $e * @access public */ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { $this->writeCase('error', 'Incomplete Test'); $this->currentTestCasePass = FALSE; } /** * Skipped test. * * @param PHPUnit2_Framework_Test $test * @param Exception $e * @access public */ public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) { $this->writeCase('error', 'Skipped Test'); $this->currentTestCasePass = FALSE; } /** * 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->currentTestSuiteName = $this->escapeValue($suite->getName()); $this->currentTestCaseName = ''; $this->currentTestMethodName = ''; } /** * 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->currentTestCaseName = ''; $this->currentTestMethodName = ''; $this->currentTestSuiteName = ''; } /** * A test started. * * @param PHPUnit2_Framework_Test $test * @access public */ public function startTest(PHPUnit2_Framework_Test $test) { $this->currentTestCaseName = $this->escapeValue(get_class($test)); $this->currentTestMethodName = $this->escapeValue($test->getName()); $this->currentTestCasePass = TRUE; } /** * A test ended. * * @param PHPUnit2_Framework_Test $test * @access public */ public function endTest(PHPUnit2_Framework_Test $test) { if ($this->currentTestCasePass) { $this->writeCase('pass'); } } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */ ?>
« previous php.pear.cvs (#39118) next »