summaryrefslogtreecommitdiff
path: root/tests/test_tools/simpletest/detached.php
blob: 4cba0ae1b949b413c35e607280d47b50c2b6c47f (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
<?php
    /**
     *	base include file for SimpleTest
     *	@package	SimpleTest
     *	@subpackage	UnitTester
     *	@version	$Id$
     */

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

    /**
     *    Runs an XML formated test in a separate process.
	 *	  @package SimpleTest
	 *	  @subpackage UnitTester
     */
    class DetachedTestCase {
        protected $_command;
        protected $_dry_command;
        protected $_size;

        /**
         *    Sets the location of the remote test.
         *    @param string $command       Test script.
         *    @param string $dry_command   Script for dry run.
         *    @access public
         */
        function DetachedTestCase($command, $dry_command = false) {
            $this->_command = $command;
            $this->_dry_command = $dry_command ? $dry_command : $command;
            $this->_size = false;
        }

        /**
         *    Accessor for the test name for subclasses.
         *    @return string       Name of the test.
         *    @access public
         */
        function getLabel() {
            return $this->_command;
        }

        /**
         *    Runs the top level test for this class. Currently
         *    reads the data as a single chunk. I'll fix this
         *    once I have added iteration to the browser.
         *    @param SimpleReporter $reporter    Target of test results.
         *    @returns boolean                   True if no failures.
         *    @access public
         */
        function run($reporter) {
			$shell = new SimpleShell();
			$shell->execute($this->_command);
            $parser = $this->_createParser($reporter);
            if (! $parser->parse($shell->getOutput())) {
                trigger_error('Cannot parse incoming XML from [' . $this->_command . ']');
                return false;
            }
            return true;
        }

        /**
         *    Accessor for the number of subtests.
         *    @return integer       Number of test cases.
         *    @access public
         */
        function getSize() {
            if ($this->_size === false) {
				$shell = new SimpleShell();
				$shell->execute($this->_dry_command);
                $reporter = new SimpleReporter();
                $parser = $this->_createParser($reporter);
                if (! $parser->parse($shell->getOutput())) {
                    trigger_error('Cannot parse incoming XML from [' . $this->_dry_command . ']');
                    return false;
                }
                $this->_size = $reporter->getTestCaseCount();
            }
            return $this->_size;
        }

        /**
         *    Creates the XML parser.
         *    @param SimpleReporter $reporter    Target of test results.
         *    @return SimpleTestXmlListener      XML reader.
         *    @access protected
         */
        function &_createParser($reporter) {
            return new SimpleTestXmlParser($reporter);
        }
    }
?>