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) {
19 $this->_command
= $command;
20 $this->_quiet
= $quiet;
23 public function getLabel() {
24 return $this->_command
;
26 public function run(&$reporter) {
27 if (!$this->_quiet
) $reporter->paintFormattedMessage('Running ['.$this->_command
.']');
28 return $this->_invokeCommand($this->_command
, $reporter);
30 public function _invokeCommand($command, &$reporter) {
31 $xml = shell_exec($command);
34 $reporter->paintFail('Command did not have any output [' . $command . ']');
38 $parser = &$this->_createParser($reporter);
40 set_error_handler(array($this, '_errorHandler'));
41 $status = $parser->parse($xml);
42 restore_error_handler();
46 foreach ($this->_errors
as $error) {
47 list($no, $str, $file, $line) = $error;
48 $reporter->paintFail("Error $no: $str on line $line of $file");
50 if (strlen($xml) > 120) {
51 $msg = substr($xml, 0, 50) . "...\n\n[snip]\n\n..." . substr($xml, -50);
55 $reporter->paintFail("Command produced malformed XML");
56 $reporter->paintFormattedMessage($msg);
62 public function &_createParser(&$reporter) {
63 $parser = new SimpleTestXmlParser($reporter);
66 public function getSize() {
67 // This code properly does the dry run and allows for proper test
68 // case reporting but it's REALLY slow, so I don't recommend it.
69 if ($this->_size
=== false) {
70 $reporter = new SimpleReporter();
71 $this->_invokeCommand($this->_command
. ' --dry', $reporter);
72 $this->_size
= $reporter->getTestCaseCount();
76 public function _errorHandler($a, $b, $c, $d) {
77 $this->_errors
[] = array($a, $b, $c, $d); // see set_error_handler()