detached.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage UnitTester
  6. * @version $Id$
  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. private $command;
  21. private $dry_command;
  22. private $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 __construct($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. protected function &createParser(&$reporter) {
  86. return new SimpleTestXmlParser($reporter);
  87. }
  88. }
  89. ?>