Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/simpletestlib/default_reporter.php
Go to the documentation of this file.
00001 <?php
00012 require_once(dirname(__FILE__) . '/simpletest.php');
00013 require_once(dirname(__FILE__) . '/scorer.php');
00014 require_once(dirname(__FILE__) . '/reporter.php');
00015 require_once(dirname(__FILE__) . '/xml.php');
00025 class SimpleCommandLineParser {
00026     var $_to_property = array(
00027             'case' => '_case', 'c' => '_case',
00028             'test' => '_test', 't' => '_test',
00029             'xml' => '_xml', 'x' => '_xml');
00030     var $_case = '';
00031     var $_test = '';
00032     var $_xml = false;
00033     var $_no_skips = false;
00034     
00039     function SimpleCommandLineParser($arguments) {
00040         if (! is_array($arguments)) {
00041             return;
00042         }
00043         foreach ($arguments as $i => $argument) {
00044             if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
00045                 $property = $this->_to_property[$matches[1]];
00046                 $this->$property = $matches[2];
00047             } elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
00048                 $property = $this->_to_property[$matches[1]];
00049                 if (isset($arguments[$i + 1])) {
00050                     $this->$property = $arguments[$i + 1];
00051                 }
00052             } elseif (preg_match('/^--?(xml|x)$/', $argument)) {
00053                 $this->_xml = true;
00054             } elseif (preg_match('/^--?(no-skip|no-skips|s)$/', $argument)) {
00055                 $this->_no_skips = true;
00056             }
00057         }
00058     }
00059     
00065     function getTest() {
00066         return $this->_test;
00067     }
00068     
00074     function getTestCase() {
00075         return $this->_case;
00076     }
00077     
00083     function isXml() {
00084         return $this->_xml;
00085     }
00086     
00092     function noSkips() {
00093         return $this->_no_skips;
00094     }
00095 }
00096 
00104 class DefaultReporter extends SimpleReporterDecorator {
00105     
00109     function DefaultReporter() {
00110         if (SimpleReporter::inCli()) {
00111             global $argv;
00112             $parser = new SimpleCommandLineParser($argv);
00113             $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
00114             $reporter = new SelectiveReporter(
00115                     SimpleTest::preferred($interfaces),
00116                     $parser->getTestCase(),
00117                     $parser->getTest());
00118             if ($parser->noSkips()) {
00119                 $reporter = new NoSkipsReporter($reporter);
00120             }
00121         } else {
00122             $reporter = new SelectiveReporter(
00123                     SimpleTest::preferred('HtmlReporter'),
00124                     @$_GET['c'],
00125                     @$_GET['t']);
00126             if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
00127                 $reporter = new NoSkipsReporter($reporter);
00128             }
00129         }
00130         $this->SimpleReporterDecorator($reporter);
00131     }
00132 }
00133 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations