123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- require_once(dirname(__FILE__) . '/simpletest.php');
- require_once(dirname(__FILE__) . '/scorer.php');
- require_once(dirname(__FILE__) . '/reporter.php');
- require_once(dirname(__FILE__) . '/xml.php');
- class SimpleCommandLineParser {
- var $_to_property = array(
- 'case' => '_case', 'c' => '_case',
- 'test' => '_test', 't' => '_test',
- 'xml' => '_xml', 'x' => '_xml');
- var $_case = '';
- var $_test = '';
- var $_xml = false;
- var $_no_skips = false;
-
- function SimpleCommandLineParser($arguments) {
- if (! is_array($arguments)) {
- return;
- }
- foreach ($arguments as $i => $argument) {
- if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
- $property = $this->_to_property[$matches[1]];
- $this->$property = $matches[2];
- } elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
- $property = $this->_to_property[$matches[1]];
- if (isset($arguments[$i + 1])) {
- $this->$property = $arguments[$i + 1];
- }
- } elseif (preg_match('/^--?(xml|x)$/', $argument)) {
- $this->_xml = true;
- } elseif (preg_match('/^--?(no-skip|no-skips|s)$/', $argument)) {
- $this->_no_skips = true;
- }
- }
- }
-
- function getTest() {
- return $this->_test;
- }
-
- function getTestCase() {
- return $this->_case;
- }
-
- function isXml() {
- return $this->_xml;
- }
-
- function noSkips() {
- return $this->_no_skips;
- }
- }
- class DefaultReporter extends SimpleReporterDecorator {
-
- 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());
- if ($parser->noSkips()) {
- $reporter = &new NoSkipsReporter($reporter);
- }
- } else {
- $reporter = &new SelectiveReporter(
- SimpleTest::preferred('HtmlReporter'),
- @$_GET['c'],
- @$_GET['t']);
- if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
- $reporter = &new NoSkipsReporter($reporter);
- }
- }
- $this->SimpleReporterDecorator($reporter);
- }
- }
- ?>
|