From 2ea6d5686f4d3ef857a030cc5bd35100b755c850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 19 Aug 2012 17:08:40 +0200 Subject: [PATCH] MDL-34893 use standard options in Hint_ResultPrinter This is a very nasty hack! --- lib/phpunit/classes/hint_resultprinter.php | 41 ++++++++++++++++++++++ phpunit.xml.dist | 1 - 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/phpunit/classes/hint_resultprinter.php b/lib/phpunit/classes/hint_resultprinter.php index 9e468110bc0..33ec7938aa2 100644 --- a/lib/phpunit/classes/hint_resultprinter.php +++ b/lib/phpunit/classes/hint_resultprinter.php @@ -34,6 +34,20 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter { + public function __construct() { + // ARRGH - PHPUnit does not give us commandline arguments or xml config, so let's hack hard! + if (defined('DEBUG_BACKTRACE_PROVIDE_OBJECT')) { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); + if (isset($backtrace[2]['object']) and ($backtrace[2]['object'] instanceof PHPUnit_TextUI_Command)) { + list($verbose, $colors, $debug) = Hacky_TextUI_Command_reader::get_settings_hackery($backtrace[2]['object']); + parent::__construct(null, $verbose, $colors, $debug); + return; + } + } + // Fallback if something goes wrong. + parent::__construct(null, false, false, false); + } + protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) { global $CFG; @@ -83,3 +97,30 @@ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter { $this->write("\nTo re-run:\n $executable $testName $file\n"); } } + + +/** + * Class used in bloody hack that works around result printer constructor troubles. + * + * @package core + * @category phpunit + * @copyright 2012 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class Hacky_TextUI_Command_reader extends PHPUnit_TextUI_Command { + public static function get_settings_hackery(PHPUnit_TextUI_Command $toread) { + $arguments = $toread->arguments; + $config = PHPUnit_Util_Configuration::getInstance($arguments['configuration'])->getPHPUnitConfiguration(); + + $verbose = isset($config['verbose']) ? $config['verbose'] : false; + $verbose = isset($arguments['verbose']) ? $arguments['verbose'] : $verbose; + + $colors = isset($config['colors']) ? $config['colors'] : false; + $colors = isset($arguments['colors']) ? $arguments['colors'] : $colors; + + $debug = isset($config['debug']) ? $config['debug'] : false; + $debug = isset($arguments['debug']) ? $arguments['debug'] : $debug; + + return array($verbose, $colors, $debug); + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7b33e948ccc..1e65824d203 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,7 +14,6 @@ stopOnIncomplete="false" stopOnSkipped="false" strict="false" - verbose="false" printerClass="Hint_ResultPrinter" >