aboutsummaryrefslogtreecommitdiff
path: root/vendors/simpletest/default_reporter.php
blob: bd4c6a19045ac1e1823f9ba1a854bfb322b9946c (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
 *  Optional include file for SimpleTest
 *  @package    SimpleTest
 *  @subpackage UnitTester
 *  @version    $Id: default_reporter.php 1704 2008-03-25 00:47:04Z lastcraft $
 */

/**#@+
 *  include other SimpleTest class files
 */
require_once(dirname(__FILE__) . '/simpletest.php');
require_once(dirname(__FILE__) . '/scorer.php');
require_once(dirname(__FILE__) . '/reporter.php');
require_once(dirname(__FILE__) . '/xml.php');
/**#@-*/

/**
 *    Parser for command line arguments. Extracts
 *    the a specific test to run and engages XML
 *    reporting when necessary.
 *    @package SimpleTest
 *    @subpackage UnitTester
 */
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;
    
    /**
     *    Parses raw command line arguments into object properties.
     *    @param string $arguments        Raw commend line arguments.
     */
    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;
            }
        }
    }
    
    /**
     *    Run only this test.
     *    @return string        Test name to run.
     *    @access public
     */
    function getTest() {
        return $this->_test;
    }
    
    /**
     *    Run only this test suite.
     *    @return string        Test class name to run.
     *    @access public
     */
    function getTestCase() {
        return $this->_case;
    }
    
    /**
     *    Output should be XML or not.
     *    @return boolean        True if XML desired.
     *    @access public
     */
    function isXml() {
        return $this->_xml;
    }
    
    /**
     *    Output should suppress skip messages.
     *    @return boolean        True for no skips.
     *    @access public
     */
    function noSkips() {
        return $this->_no_skips;
    }
}

/**
 *    The default reporter used by SimpleTest's autorun
 *    feature. The actual reporters used are dependency
 *    injected and can be overridden.
 *    @package SimpleTest
 *    @subpackage UnitTester
 */
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());
            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);
    }
}
?>