4 * Implements an external test-case like RemoteTestCase that parses its
5 * output from XML returned by a command line call
11 public $_quiet = false;
12 public $_errors = array();
13 public $_size = false;
15 * @param $command Command to execute to retrieve XML
16 * @param $xml Whether or not to suppress error messages
18 public function __construct($command, $quiet = false, $size = false)
20 $this->_command
= $command;
21 $this->_quiet
= $quiet;
24 public function getLabel()
26 return $this->_command
;
28 public function run($reporter)
30 if (!$this->_quiet
) $reporter->paintFormattedMessage('Running ['.$this->_command
.']');
31 return $this->_invokeCommand($this->_command
, $reporter);
33 public function _invokeCommand($command, $reporter)
35 $xml = shell_exec($command);
38 $reporter->paintFail('Command did not have any output [' . $command . ']');
42 $parser = $this->_createParser($reporter);
44 set_error_handler(array($this, '_errorHandler'));
45 $status = $parser->parse($xml);
46 restore_error_handler();
50 foreach ($this->_errors
as $error) {
51 list($no, $str, $file, $line) = $error;
52 $reporter->paintFail("Error $no: $str on line $line of $file");
54 if (strlen($xml) > 120) {
55 $msg = substr($xml, 0, 50) . "...\n\n[snip]\n\n..." . substr($xml, -50);
59 $reporter->paintFail("Command produced malformed XML");
60 $reporter->paintFormattedMessage($msg);
66 public function _createParser($reporter)
68 $parser = new SimpleTestXmlParser($reporter);
71 public function getSize()
73 // This code properly does the dry run and allows for proper test
74 // case reporting but it's REALLY slow, so I don't recommend it.
75 if ($this->_size
=== false) {
76 $reporter = new SimpleReporter();
77 $this->_invokeCommand($this->_command
. ' --dry', $reporter);
78 $this->_size
= $reporter->getTestCaseCount();
82 public function _errorHandler($a, $b, $c, $d)
84 $this->_errors
[] = array($a, $b, $c, $d); // see set_error_handler()