blob: 8a760353d48413d1f7a91e55dfb83195393e9105 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?php
// $Id$
/**
* Parser for command line arguments. Extracts
* the a specific test to run and engages XML
* reporting when necessary.
*/
class SimpleCommandLineParser {
protected $to_property = array('c' => 'case', 't' => 'test');
protected $case = '';
protected $test = '';
protected $xml = false;
function SimpleCommandLineParser($arguments) {
if (!is_array($arguments)) {
return;
}
foreach ($arguments as $i => $argument) {
if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
$this->{$this->_parseProperty($matches[1])} = $matches[2];
}
elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
if (isset($arguments[$i + 1])) {
$this->{$this->_parseProperty($matches[1])} = $arguments[$i + 1];
}
}
elseif (preg_match('/^--?(xml|x)$/', $argument)) {
$this->xml = true;
}
}
}
function _parseProperty($property) {
if (isset($this->to_property[$property])) {
return $this->to_property[$property];
}
else {
return $property;
}
}
function getTest() {
return $this->test;
}
function getTestCase() {
return $this->case;
}
function isXml() {
return $this->xml;
}
}
/**
* The default reporter used by SimpleTest's autorun
* feature. The actual reporters used are dependency
* injected and can be overridden.
*/
class DefaultReporter extends SimpleReporterDecorator {
/**
* Assembles the appopriate reporter for the environment.
*/
function DefaultReporter() {
if (SimpleReporter::inCli()) {
global $argv;
$parser = new SimpleCommandLineParser($argv);
$interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
$reporter = &new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
}
else {
$reporter = &new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
}
$this->SimpleReporterDecorator($reporter);
}
}
|