Source for file remote.php

Documentation is available at remote.php

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

Documentation generated on Sun, 04 May 2008 09:22:00 -0500 by phpDocumentor 1.3.0