PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/application/libraries/simpletest/remote.php

https://bitbucket.org/mercucci/mercucci
PHP | 117 lines | 58 code | 8 blank | 51 comment | 5 complexity | 700570be16c097cb0f44c78ecfada5d7 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage UnitTester
  6. * @version $Id: remote.php 1723 2008-04-08 00:34:10Z lastcraft $
  7. */
  8. /**#@+
  9. * include other SimpleTest class files
  10. */
  11. require_once(dirname(__FILE__) . '/browser.php');
  12. require_once(dirname(__FILE__) . '/xml.php');
  13. require_once(dirname(__FILE__) . '/test_case.php');
  14. /**#@-*/
  15. /**
  16. * Runs an XML formated test on a remote server.
  17. * @package SimpleTest
  18. * @subpackage UnitTester
  19. */
  20. class RemoteTestCase {
  21. var $_url;
  22. var $_dry_url;
  23. var $_size;
  24. /**
  25. * Sets the location of the remote test.
  26. * @param string $url Test location.
  27. * @param string $dry_url Location for dry run.
  28. * @access public
  29. */
  30. function RemoteTestCase($url, $dry_url = false) {
  31. $this->_url = $url;
  32. $this->_dry_url = $dry_url ? $dry_url : $url;
  33. $this->_size = false;
  34. }
  35. /**
  36. * Accessor for the test name for subclasses.
  37. * @return string Name of the test.
  38. * @access public
  39. */
  40. function getLabel() {
  41. return $this->_url;
  42. }
  43. /**
  44. * Runs the top level test for this class. Currently
  45. * reads the data as a single chunk. I'll fix this
  46. * once I have added iteration to the browser.
  47. * @param SimpleReporter $reporter Target of test results.
  48. * @returns boolean True if no failures.
  49. * @access public
  50. */
  51. function run(&$reporter) {
  52. $browser = &$this->_createBrowser();
  53. $xml = $browser->get($this->_url);
  54. if (! $xml) {
  55. trigger_error('Cannot read remote test URL [' . $this->_url . ']');
  56. return false;
  57. }
  58. $parser = &$this->_createParser($reporter);
  59. if (! $parser->parse($xml)) {
  60. trigger_error('Cannot parse incoming XML from [' . $this->_url . ']');
  61. return false;
  62. }
  63. return true;
  64. }
  65. /**
  66. * Creates a new web browser object for fetching
  67. * the XML report.
  68. * @return SimpleBrowser New browser.
  69. * @access protected
  70. */
  71. function &_createBrowser() {
  72. $browser = &new SimpleBrowser();
  73. return $browser;
  74. }
  75. /**
  76. * Creates the XML parser.
  77. * @param SimpleReporter $reporter Target of test results.
  78. * @return SimpleTestXmlListener XML reader.
  79. * @access protected
  80. */
  81. function &_createParser(&$reporter) {
  82. $parser = &new SimpleTestXmlParser($reporter);
  83. return $parser;
  84. }
  85. /**
  86. * Accessor for the number of subtests.
  87. * @return integer Number of test cases.
  88. * @access public
  89. */
  90. function getSize() {
  91. if ($this->_size === false) {
  92. $browser = &$this->_createBrowser();
  93. $xml = $browser->get($this->_dry_url);
  94. if (! $xml) {
  95. trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']');
  96. return false;
  97. }
  98. $reporter = &new SimpleReporter();
  99. $parser = &$this->_createParser($reporter);
  100. if (! $parser->parse($xml)) {
  101. trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']');
  102. return false;
  103. }
  104. $this->_size = $reporter->getTestCaseCount();
  105. }
  106. return $this->_size;
  107. }
  108. }
  109. ?>