detached.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage UnitTester
  6. * @version $Id: detached.php 1723 2008-04-08 00:34:10Z lastcraft $
  7. */
  8. /**#@+
  9. * include other SimpleTest class files
  10. */
  11. require_once(dirname(__FILE__) . '/xml.php');
  12. require_once(dirname(__FILE__) . '/shell_tester.php');
  13. /**#@-*/
  14. /**
  15. * Runs an XML formated test in a separate process.
  16. * @package SimpleTest
  17. * @subpackage UnitTester
  18. */
  19. class DetachedTestCase {
  20. var $_command;
  21. var $_dry_command;
  22. var $_size;
  23. /**
  24. * Sets the location of the remote test.
  25. * @param string $command Test script.
  26. * @param string $dry_command Script for dry run.
  27. * @access public
  28. */
  29. function DetachedTestCase($command, $dry_command = false) {
  30. $this->_command = $command;
  31. $this->_dry_command = $dry_command ? $dry_command : $command;
  32. $this->_size = false;
  33. }
  34. /**
  35. * Accessor for the test name for subclasses.
  36. * @return string Name of the test.
  37. * @access public
  38. */
  39. function getLabel() {
  40. return $this->_command;
  41. }
  42. /**
  43. * Runs the top level test for this class. Currently
  44. * reads the data as a single chunk. I'll fix this
  45. * once I have added iteration to the browser.
  46. * @param SimpleReporter $reporter Target of test results.
  47. * @returns boolean True if no failures.
  48. * @access public
  49. */
  50. function run(&$reporter) {
  51. $shell = &new SimpleShell();
  52. $shell->execute($this->_command);
  53. $parser = &$this->_createParser($reporter);
  54. if (! $parser->parse($shell->getOutput())) {
  55. trigger_error('Cannot parse incoming XML from [' . $this->_command . ']');
  56. return false;
  57. }
  58. return true;
  59. }
  60. /**
  61. * Accessor for the number of subtests.
  62. * @return integer Number of test cases.
  63. * @access public
  64. */
  65. function getSize() {
  66. if ($this->_size === false) {
  67. $shell = &new SimpleShell();
  68. $shell->execute($this->_dry_command);
  69. $reporter = &new SimpleReporter();
  70. $parser = &$this->_createParser($reporter);
  71. if (! $parser->parse($shell->getOutput())) {
  72. trigger_error('Cannot parse incoming XML from [' . $this->_dry_command . ']');
  73. return false;
  74. }
  75. $this->_size = $reporter->getTestCaseCount();
  76. }
  77. return $this->_size;
  78. }
  79. /**
  80. * Creates the XML parser.
  81. * @param SimpleReporter $reporter Target of test results.
  82. * @return SimpleTestXmlListener XML reader.
  83. * @access protected
  84. */
  85. function &_createParser(&$reporter) {
  86. return new SimpleTestXmlParser($reporter);
  87. }
  88. }
  89. ?>