[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Helper test listener. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2012 Petr Skoda {@link http://skodak.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 /** 28 * Helper test listener that prints command necessary 29 * for execution of failed test. 30 * 31 * @package core 32 * @category phpunit 33 * @copyright 2012 Petr Skoda {@link http://skodak.org} 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter { 37 public function __construct() { 38 // ARRGH - PHPUnit does not give us commandline arguments or xml config, so let's hack hard! 39 if (defined('DEBUG_BACKTRACE_PROVIDE_OBJECT')) { 40 $backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); 41 if (isset($backtrace[2]['object']) and ($backtrace[2]['object'] instanceof PHPUnit_TextUI_Command)) { 42 list($verbose, $colors, $debug) = Hacky_TextUI_Command_reader::get_settings_hackery($backtrace[2]['object']); 43 parent::__construct(null, $verbose, $colors, $debug); 44 return; 45 } 46 } 47 // Fallback if something goes wrong. 48 parent::__construct(null, false, self::COLOR_DEFAULT, false); 49 } 50 51 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect) { 52 global $CFG; 53 54 parent::printDefectTrace($defect); 55 56 $failedTest = $defect->failedTest(); 57 $testName = get_class($failedTest); 58 59 $exception = $defect->thrownException(); 60 $trace = $exception->getTrace(); 61 62 if (class_exists('ReflectionClass')) { 63 $reflection = new ReflectionClass($testName); 64 $file = $reflection->getFileName(); 65 66 } else { 67 $file = false; 68 $dirroot = realpath($CFG->dirroot).DIRECTORY_SEPARATOR; 69 $classpath = realpath("$CFG->dirroot/lib/phpunit/classes").DIRECTORY_SEPARATOR; 70 foreach ($trace as $item) { 71 if (strpos($item['file'], $dirroot) === 0 and strpos($item['file'], $classpath) !== 0) { 72 if ($content = file_get_contents($item['file'])) { 73 if (preg_match('/class\s+'.$testName.'\s+extends/', $content)) { 74 $file = $item['file']; 75 break; 76 } 77 } 78 } 79 } 80 } 81 82 if ($file === false) { 83 return; 84 } 85 86 $cwd = getcwd(); 87 if (strpos($file, $cwd) === 0) { 88 $file = substr($file, strlen($cwd)+1); 89 } 90 91 $executable = null; 92 93 if (isset($_SERVER['argv'][0])) { 94 if (preg_match('/phpunit(\.bat|\.cmd)?$/', $_SERVER['argv'][0])) { 95 $executable = $_SERVER['argv'][0]; 96 for($i=1;$i<count($_SERVER['argv']);$i++) { 97 if (!isset($_SERVER['argv'][$i])) { 98 break; 99 } 100 if (in_array($_SERVER['argv'][$i], array('--colors', '--verbose', '-v', '--debug', '--strict'))) { 101 $executable .= ' '.$_SERVER['argv'][$i]; 102 } 103 } 104 } 105 } 106 107 if (!$executable) { 108 $executable = 'phpunit'; 109 if (testing_is_cygwin()) { 110 $file = str_replace('\\', '/', $file); 111 if (!testing_is_mingw()) { 112 $executable = 'phpunit.bat'; 113 } 114 } 115 } 116 117 $this->write("\nTo re-run:\n $executable $testName $file\n"); 118 } 119 } 120 121 122 /** 123 * Class used in bloody hack that works around result printer constructor troubles. 124 * 125 * @package core 126 * @category phpunit 127 * @copyright 2012 Petr Skoda {@link http://skodak.org} 128 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 129 */ 130 class Hacky_TextUI_Command_reader extends PHPUnit_TextUI_Command { 131 public static function get_settings_hackery(PHPUnit_TextUI_Command $toread) { 132 $arguments = $toread->arguments; 133 $config = PHPUnit_Util_Configuration::getInstance($arguments['configuration'])->getPHPUnitConfiguration(); 134 135 $verbose = isset($config['verbose']) ? $config['verbose'] : false; 136 $verbose = isset($arguments['verbose']) ? $arguments['verbose'] : $verbose; 137 138 $colors = isset($config['colors']) ? $config['colors'] : Hint_ResultPrinter::COLOR_DEFAULT; 139 $colors = isset($arguments['colors']) ? $arguments['colors'] : $colors; 140 141 $debug = isset($config['debug']) ? $config['debug'] : false; 142 $debug = isset($arguments['debug']) ? $arguments['debug'] : $debug; 143 144 return array($verbose, $colors, $debug); 145 } 146 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |