3 * Optional include file for SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: default_reporter.php 2011 2011-04-29 08:22:48Z pp11 $
10 * include other SimpleTest class files
12 require_once(dirname(__FILE__
) . '/simpletest.php');
13 require_once(dirname(__FILE__
) . '/scorer.php');
14 require_once(dirname(__FILE__
) . '/reporter.php');
15 require_once(dirname(__FILE__
) . '/xml.php');
19 * Parser for command line arguments. Extracts
20 * the a specific test to run and engages XML
21 * reporting when necessary.
23 * @subpackage UnitTester
25 class SimpleCommandLineParser
{
26 private $to_property = array(
27 'case' => 'case', 'c' => 'case',
28 'test' => 'test', 't' => 'test',
33 private $help = false;
34 private $no_skips = false;
37 * Parses raw command line arguments into object properties.
38 * @param string $arguments Raw commend line arguments.
40 function __construct($arguments) {
41 if (! is_array($arguments)) {
44 foreach ($arguments as $i => $argument) {
45 if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
46 $property = $this->to_property
[$matches[1]];
47 $this->$property = $matches[2];
48 } elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
49 $property = $this->to_property
[$matches[1]];
50 if (isset($arguments[$i +
1])) {
51 $this->$property = $arguments[$i +
1];
53 } elseif (preg_match('/^--?(xml|x)$/', $argument)) {
55 } elseif (preg_match('/^--?(no-skip|no-skips|s)$/', $argument)) {
56 $this->no_skips
= true;
57 } elseif (preg_match('/^--?(help|h)$/', $argument)) {
65 * @return string Test name to run.
72 * Run only this test suite.
73 * @return string Test class name to run.
75 function getTestCase() {
80 * Output should be XML or not.
81 * @return boolean True if XML desired.
88 * Output should suppress skip messages.
89 * @return boolean True for no skips.
92 return $this->no_skips
;
96 * Output should be a help message. Disabled during XML mode.
97 * @return boolean True if help message desired.
100 return $this->help
&& ! $this->xml
;
104 * Returns plain-text help message for command line runner.
105 * @return string String help message
107 function getHelpText() {
109 SimpleTest command line default reporter (autorun)
110 Usage: php <test_file> [args...]
112 -c <class> Run only the test-case <class>
113 -t <method> Run only the test method <method>
114 -s Suppress skip messages
115 -x Return test results in XML
116 -h Display this help message
124 * The default reporter used by SimpleTest's autorun
125 * feature. The actual reporters used are dependency
126 * injected and can be overridden.
127 * @package SimpleTest
128 * @subpackage UnitTester
130 class DefaultReporter
extends SimpleReporterDecorator
{
133 * Assembles the appropriate reporter for the environment.
135 function __construct() {
136 if (SimpleReporter
::inCli()) {
137 $parser = new SimpleCommandLineParser($_SERVER['argv']);
138 $interfaces = $parser->isXml() ?
array('XmlReporter') : array('TextReporter');
139 if ($parser->help()) {
140 // I'm not sure if we should do the echo'ing here -- ezyang
141 echo $parser->getHelpText();
144 $reporter = new SelectiveReporter(
145 SimpleTest
::preferred($interfaces),
146 $parser->getTestCase(),
148 if ($parser->noSkips()) {
149 $reporter = new NoSkipsReporter($reporter);
152 $reporter = new SelectiveReporter(
153 SimpleTest
::preferred('HtmlReporter'),
156 if (@$_GET['skips'] == 'no' ||
@$_GET['show-skips'] == 'no') {
157 $reporter = new NoSkipsReporter($reporter);
160 parent
::__construct($reporter);