cvs: pear /PHPUnit2/TextUI TestRunner.php /PHPUnit2/Util/Log GraphViz.php

From: Date: Thu, 02 Mar 2006 11:16:52 +0000
Subject: cvs: pear /PHPUnit2/TextUI TestRunner.php /PHPUnit2/Util/Log GraphViz.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38846@lists.php.net to get a copy of this message
sebastian Thu Mar 2 11:16:52 2006 UTC Modified files: /pear/PHPUnit2/TextUI TestRunner.php /pear/PHPUnit2/Util/Log GraphViz.php Log: Generating one big graph is not suitable for larger test suites.

http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/TextUI/TestRunner.php?r1=1.87&r2=1.88&diff_format=u Index: pear/PHPUnit2/TextUI/TestRunner.php diff -u pear/PHPUnit2/TextUI/TestRunner.php:1.87 pear/PHPUnit2/TextUI/TestRunner.php:1.88 --- pear/PHPUnit2/TextUI/TestRunner.php:1.87 Wed Mar 1 14:31:42 2006 +++ pear/PHPUnit2/TextUI/TestRunner.php Thu Mar 2 11:16:52 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.87 2006/03/01 14:31:42 sebastian Exp $ + * @version CVS: $Id: TestRunner.php,v 1.88 2006/03/02 11:16:52 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 2.0.0 */ @@ -153,7 +153,7 @@ $coverageTextFile = FALSE; $testdoxHTMLFile = FALSE; $testdoxTextFile = FALSE; - $graphvizLogfile = FALSE; + $graphvizDirectory = FALSE; $tapLogfile = FALSE; $xmlLogfile = FALSE; $wait = FALSE; @@ -205,10 +205,6 @@ case '--coverage-html': { $coverageHTMLDirectory = $option[1]; - - if (substr($coverageHTMLDirectory, -1, 1) != DIRECTORY_SEPARATOR) { - $coverageHTMLDirectory .= DIRECTORY_SEPARATOR; - } } break; @@ -253,7 +249,7 @@ break; case '--log-graphviz': { - $graphvizLogfile = $option[1]; + $graphvizDirectory = $option[1]; } break; @@ -341,7 +337,7 @@ $coverageTextFile, $testdoxHTMLFile, $testdoxTextFile, - $graphvizLogfile, + $graphvizDirectory, $tapLogfile, $xmlLogfile, $wait @@ -360,14 +356,14 @@ * @param mixed $coverageDataFile * @param mixed $testdoxHTMLFile * @param mixed $testdoxTextFile - * @param mixed $graphvizLogfile + * @param mixed $graphvizDirectory * @param mixed $tapLogfile * @param mixed $xmlLogfile * @param boolean $wait * @access public * @static */ - public static function run($test, $coverageDataFile = FALSE, $coverageHTMLDirectory = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizLogfile = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) + public static function run($test, $coverageDataFile = FALSE, $coverageHTMLDirectory = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizDirectory = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) { if ($test instanceof ReflectionClass) { $test = new PHPUnit2_Framework_TestSuite($test); @@ -383,7 +379,7 @@ $coverageTextFile, $testdoxHTMLFile, $testdoxTextFile, - $graphvizLogfile, + $graphvizDirectory, $tapLogfile, $xmlLogfile, $wait @@ -430,15 +426,23 @@ * @param mixed $coverageTextFile * @param mixed $testdoxHTMLFile * @param mixed $testdoxTextFile - * @param mixed $graphvizLogfile + * @param mixed $graphvizDirectory * @param mixed $tapLogfile * @param mixed $xmlLogfile * @param boolean $wait * @return PHPUnit2_Framework_TestResult * @access public */ - public function doRun(PHPUnit2_Framework_Test $suite, $coverageDataFile = FALSE, $coverageHTMLDirectory = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizLogfile = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) + public function doRun(PHPUnit2_Framework_Test $suite, $coverageDataFile = FALSE, $coverageHTMLDirectory = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $graphvizDirectory = FALSE, $tapLogfile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) { + if ($coverageHTMLDirectory !== FALSE) { + $coverageHTMLDirectory = $this->getDirectory($coverageHTMLDirectory); + } + + if ($graphvizDirectory !== FALSE) { + $graphvizDirectory = $this->getDirectory($graphvizDirectory); + } + $result = $this->createTestResult(); if ($this->printer === NULL) { @@ -471,9 +475,9 @@ } } - if ($graphvizLogfile !== FALSE) { + if ($graphvizDirectory !== FALSE) { $result->addListener( - new PHPUnit2_Util_Log_GraphViz($graphvizLogfile) + new PHPUnit2_Util_Log_GraphViz($graphvizDirectory) ); } @@ -497,7 +501,7 @@ if (class_exists('Image_GraphViz') && $coverageHTMLDirectory !== FALSE) { $result->addListener( new PHPUnit2_Util_Log_GraphViz( - $coverageHTMLDirectory . 'testmap.dot' + $coverageHTMLDirectory ) ); } @@ -605,7 +609,7 @@ " --testdox-text <file> Write agile documentation in Text format to file.\n"; if (class_exists('Image_GraphViz')) { - print" --log-graphviz <file> Log test progress in GraphViz markup to file.\n"; + print" --log-graphviz <dir> Log test progress in GraphViz markup.\n"; } print " --log-tap <file> Log test progress in TAP format to file.\n" . @@ -699,6 +703,19 @@ self::$versionStringPrinted = TRUE; } } + + /** + * @access private + * @since Method available since Release 3.0.0 + */ + private function getDirectory($directory) + { + if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) { + $directory .= DIRECTORY_SEPARATOR; + } + + return $directory; + } } if (PHPUnit2_MAIN_METHOD == 'PHPUnit2_TextUI_TestRunner::main') { http://cvs.php.net/viewcvs.cgi/pear/PHPUnit2/Util/Log/GraphViz.php?r1=1.11&r2=1.12&diff_format=u Index: pear/PHPUnit2/Util/Log/GraphViz.php diff -u pear/PHPUnit2/Util/Log/GraphViz.php:1.11 pear/PHPUnit2/Util/Log/GraphViz.php:1.12 --- pear/PHPUnit2/Util/Log/GraphViz.php:1.11 Wed Mar 1 14:31:42 2006 +++ pear/PHPUnit2/Util/Log/GraphViz.php Thu Mar 2 11:16:52 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: GraphViz.php,v 1.11 2006/03/01 14:31:42 sebastian Exp $ + * @version CVS: $Id: GraphViz.php,v 1.12 2006/03/02 11:16:52 sebastian Exp $ * @link http://pear.php.net/package/PHPUnit2 * @since File available since Release 3.0.0 */ @@ -57,7 +57,6 @@ 'PHPUnit2_Framework_Test', 'PHPUnit2_Framework_TestListener', 'PHPUnit2_Framework_TestSuite', - 'PHPUnit2_Util_Printer', 'PHPUnit2_Util_Test', 'PHPUnit2_Util_Timer', ) @@ -66,7 +65,7 @@ PHPUnit2_Util_Filter::addFileToFilter(__FILE__); /** - * A TestListener that generates a map of the executed tests + * A TestListener that generates maps of the executed tests * in GraphViz markup. * * @category Testing @@ -78,13 +77,19 @@ * @link http://pear.php.net/package/PHPUnit2 * @since Class available since Release 3.0.0 */ -class PHPUnit2_Util_Log_GraphViz extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener +class PHPUnit2_Util_Log_GraphViz implements PHPUnit2_Framework_TestListener { /** - * @var Image_GraphViz + * @var Image_GraphViz[] * @access private */ - private $graph; + private $graphs = array(); + + /** + * @var string + * @access private + */ + private $target; /** * @var boolean @@ -119,34 +124,12 @@ /** * Constructor. * - * @param mixed $out - * @access public - */ - public function __construct($out = NULL) - { - $this->graph = new Image_GraphViz( - TRUE, - array( - 'overlap' => 'scale', - 'splines' => 'true', - 'sep' => '.1', - 'fontsize' => '8' - ) - ); - - parent::__construct($out); - } - - /** - * Flush buffer and close output. - * + * @param string $target * @access public */ - public function flush() + public function __construct($target) { - $this->write($this->graph->parse()); - - parent::flush(); + $this->target = $target; } /** @@ -217,20 +200,45 @@ */ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { - $this->graph->addNode($suite->getName()); + $this->testSuiteLevel++; + $this->testSuites[$this->testSuiteLevel] = $suite->getName(); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] = 0; + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] = 0; - if ($this->testSuiteLevel > 0) { - $this->graph->addEdge( + $this->graphs[$this->testSuiteLevel] = new Image_GraphViz( + TRUE, + array( + 'overlap' => 'scale', + 'splines' => 'true', + 'sep' => '.1', + 'fontsize' => '8' + ) + ); + + $this->graphs[$this->testSuiteLevel]->addNode($suite->getName()); + + if ($this->testSuiteLevel > 1) { + $this->graphs[$this->testSuiteLevel]->addNode( + $this->testSuites[$this->testSuiteLevel - 1], array( - $this->testSuites[$this->testSuiteLevel] => $suite->getName() + 'URL' => $this->testSuites[$this->testSuiteLevel - 1] . '.htm' ) ); - } - $this->testSuiteLevel++; - $this->testSuites[$this->testSuiteLevel] = $suite->getName(); - $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] = 0; - $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] = 0; + $this->graphs[$this->testSuiteLevel]->addEdge( + array( + $this->testSuites[$this->testSuiteLevel - 1] => $suite->getName() + ) + ); + + $this->graphs[$this->testSuiteLevel - 1]->addNode($suite->getName()); + + $this->graphs[$this->testSuiteLevel - 1]->addEdge( + array( + $this->testSuites[$this->testSuiteLevel - 1] => $suite->getName() + ) + ); + } } /** @@ -253,7 +261,7 @@ $color = 'yellow'; } - $this->graph->addNode( + $this->graphs[$this->testSuiteLevel]->addNode( $this->testSuites[$this->testSuiteLevel], array( 'color' => $color, @@ -262,10 +270,22 @@ ); if ($this->testSuiteLevel > 1) { + $this->graphs[$this->testSuiteLevel - 1]->addNode( + $this->testSuites[$this->testSuiteLevel], + array( + 'color' => $color, + 'URL' => $suite->getName() . '.htm' + ) + ); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel - 1] += $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]; $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel - 1] += $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]; } + $fp = fopen($this->target . $suite->getName() . '.dot', 'w'); + fputs($fp, $this->graphs[$this->testSuiteLevel]->parse()); + fclose($fp); + $this->testSuiteLevel--; } @@ -302,7 +322,7 @@ { $name = PHPUnit2_Util_Test::describe($test, FALSE); - $this->graph->addNode( + $this->graphs[$this->testSuiteLevel]->addNode( $name[1], array( 'color' => $color, @@ -316,7 +336,7 @@ $this->testSuites[$this->testSuiteLevel] ); - $this->graph->addEdge( + $this->graphs[$this->testSuiteLevel]->addEdge( array( $this->testSuites[$this->testSuiteLevel] => $name[1] )
« previous php.pear.cvs (#38846) next »