00001 <?php
00002
00003
00009 class SimpleCommandLineParser {
00010 protected $to_property = array('c' => 'case', 't' => 'test');
00011 protected $case = '';
00012 protected $test = '';
00013 protected $xml = false;
00014
00015 function SimpleCommandLineParser($arguments) {
00016 if (!is_array($arguments)) {
00017 return;
00018 }
00019 foreach ($arguments as $i => $argument) {
00020 if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
00021 $this->{$this->_parseProperty($matches[1])} = $matches[2];
00022 }
00023 elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
00024 if (isset($arguments[$i + 1])) {
00025 $this->{$this->_parseProperty($matches[1])} = $arguments[$i + 1];
00026 }
00027 }
00028 elseif (preg_match('/^--?(xml|x)$/', $argument)) {
00029 $this->xml = true;
00030 }
00031 }
00032 }
00033 function _parseProperty($property) {
00034 if (isset($this->to_property[$property])) {
00035 return $this->to_property[$property];
00036 }
00037 else {
00038 return $property;
00039 }
00040 }
00041 function getTest() {
00042 return $this->test;
00043 }
00044
00045 function getTestCase() {
00046 return $this->case;
00047 }
00048
00049 function isXml() {
00050 return $this->xml;
00051 }
00052 }
00053
00059 class DefaultReporter extends SimpleReporterDecorator {
00063 function DefaultReporter() {
00064 if (SimpleReporter::inCli()) {
00065 global $argv;
00066 $parser = new SimpleCommandLineParser($argv);
00067 $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
00068 $reporter = &new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
00069 }
00070 else {
00071 $reporter = &new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
00072 }
00073 $this->SimpleReporterDecorator($reporter);
00074 }
00075 }