[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/test_tools/simpletest/ -> runner.php (source)

   1  <?php
   2      /**
   3       *    Base include file for SimpleTest
   4       *    @package    SimpleTest
   5       *    @subpackage    UnitTester
   6       *    @version    $Id: runner.php 1397 2006-09-07 07:55:53Z wei $
   7       */
   8      
   9      /**#@+
  10       * Includes SimpleTest files and defined the root constant
  11       * for dependent libraries.
  12       */
  13      require_once(dirname(__FILE__) . '/errors.php');
  14      require_once(dirname(__FILE__) . '/options.php');
  15      require_once(dirname(__FILE__) . '/scorer.php');
  16      require_once(dirname(__FILE__) . '/expectation.php');
  17      require_once(dirname(__FILE__) . '/dumper.php');
  18      if (! defined('SIMPLE_TEST')) {
  19          define('SIMPLE_TEST', dirname(__FILE__) . '/');
  20      }
  21      /**#@-*/
  22      
  23      /**
  24       *    This is called by the class runner to run a
  25       *    single test method. Will also run the setUp()
  26       *    and tearDown() methods.
  27       *      @package SimpleTest
  28       *      @subpackage UnitTester
  29       */
  30      class SimpleInvoker {
  31          protected $_test_case;
  32          
  33          /**
  34           *    Stashes the test case for later.
  35           *    @param SimpleTestCase $test_case  Test case to run.
  36           */
  37          function SimpleInvoker($test_case) {
  38              $this->_test_case = $test_case;
  39          }
  40          
  41          /**
  42           *    Accessor for test case being run.
  43           *    @return SimpleTestCase    Test case.
  44           *    @access public
  45           */
  46          function getTestCase() {
  47              return $this->_test_case;
  48          }
  49          
  50          /**
  51           *    Invokes a test method and buffered with setUp()
  52           *    and tearDown() calls.
  53           *    @param string $method    Test method to call.
  54           *    @access public
  55           */
  56          function invoke($method) {
  57              $this->_test_case->setUp();
  58              $this->_test_case->$method();
  59              $this->_test_case->tearDown();
  60          }
  61      }
  62      
  63      /**
  64       *    Do nothing decorator. Just passes the invocation
  65       *    straight through.
  66       *      @package SimpleTest
  67       *      @subpackage UnitTester
  68       */
  69      class SimpleInvokerDecorator {
  70          protected $_invoker;
  71          
  72          /**
  73           *    Stores the invoker to wrap.
  74           *    @param SimpleInvoker $invoker  Test method runner.
  75           */
  76          function SimpleInvokerDecorator($invoker) {
  77              $this->_invoker = $invoker;
  78          }
  79          
  80          /**
  81           *    Accessor for test case being run.
  82           *    @return SimpleTestCase    Test case.
  83           *    @access public
  84           */
  85          function getTestCase() {
  86              return $this->_invoker->getTestCase();
  87          }
  88          
  89          /**
  90           *    Invokes a test method and buffered with setUp()
  91           *    and tearDown() calls.
  92           *    @param string $method    Test method to call.
  93           *    @access public
  94           */
  95          function invoke($method) {
  96              $this->_invoker->invoke($method);
  97          }
  98      }
  99  
 100      /**
 101       *    Extension that traps errors into an error queue.
 102       *      @package SimpleTest
 103       *      @subpackage UnitTester
 104       */
 105      class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator {
 106          
 107          /**
 108          /**
 109           *    Stores the invoker to wrap.
 110           *    @param SimpleInvoker $invoker  Test method runner.
 111           */
 112          function SimpleErrorTrappingInvoker($invoker) {
 113              $this->SimpleInvokerDecorator($invoker);
 114          }
 115          
 116          /**
 117           *    Invokes a test method and dispatches any
 118           *    untrapped errors. Called back from
 119           *    the visiting runner.
 120           *    @param string $method    Test method to call.
 121           *    @access public
 122           */
 123          function invoke($method) {
 124              set_error_handler('simpleTestErrorHandler');
 125              parent::invoke($method);
 126              $queue = SimpleErrorQueue::instance();
 127              while (list($severity, $message, $file, $line, $globals) = $queue->extract()) {
 128                  $test_case = $this->getTestCase();
 129                  $test_case->error($severity, $message, $file, $line, $globals);
 130              }
 131              restore_error_handler();
 132          }
 133      }
 134  
 135      /**
 136       *    The standard runner. Will run every method starting
 137       *    with test Basically the
 138       *    Mediator pattern.
 139       *      @package SimpleTest
 140       *      @subpackage UnitTester
 141       */
 142      class SimpleRunner {
 143          protected $_test_case;
 144          protected $_scorer;
 145          
 146          /**
 147           *    Takes in the test case and reporter to mediate between.
 148           *    @param SimpleTestCase $test_case  Test case to run.
 149           *    @param SimpleScorer $scorer       Reporter to receive events.
 150           */
 151          function SimpleRunner($test_case, $scorer) {
 152              $this->_test_case = $test_case;
 153              $this->_scorer = $scorer;
 154          }
 155          
 156          /**
 157           *    Accessor for test case being run.
 158           *    @return SimpleTestCase    Test case.
 159           *    @access public
 160           */
 161          function getTestCase() {
 162              return $this->_test_case;
 163          }
 164          
 165          /**
 166           *    Runs the test methods in the test case.
 167           *    @param SimpleTest $test_case    Test case to run test on.
 168           *    @param string $method           Name of test method.
 169           *    @access public
 170           */
 171          function run() {
 172              $methods = get_class_methods(get_class($this->_test_case));
 173              $invoker = $this->_test_case->createInvoker();
 174              foreach ($methods as $method) {
 175                  if (! $this->_isTest($method)) {
 176                      continue;
 177                  }
 178                  if ($this->_isConstructor($method)) {
 179                      continue;
 180                  }
 181                  $this->_scorer->paintMethodStart($method);
 182                  if ($this->_scorer->shouldInvoke($this->_test_case->getLabel(), $method)) {
 183                      $invoker->invoke($method);
 184                  }
 185                  $this->_scorer->paintMethodEnd($method);
 186              }
 187          }
 188          
 189          /**
 190           *    Tests to see if the method is the constructor and
 191           *    so should be ignored.
 192           *    @param string $method        Method name to try.
 193           *    @return boolean              True if constructor.
 194           *    @access protected
 195           */
 196          function _isConstructor($method) {
 197              return SimpleTestCompatibility::isA(
 198                      $this->_test_case,
 199                      strtolower($method));
 200          }
 201          
 202          /**
 203           *    Tests to see if the method is a test that should
 204           *    be run. Currently any method that starts with 'test'
 205           *    is a candidate.
 206           *    @param string $method        Method name to try.
 207           *    @return boolean              True if test method.
 208           *    @access protected
 209           */
 210          function _isTest($method) {
 211              return strtolower(substr($method, 0, 4)) == 'test';
 212          }
 213  
 214          /**
 215           *    Paints the start of a test method.
 216           *    @param string $test_name     Name of test or other label.
 217           *    @access public
 218           */
 219          function paintMethodStart($test_name) {
 220              $this->_scorer->paintMethodStart($test_name);
 221          }
 222          
 223          /**
 224           *    Paints the end of a test method.
 225           *    @param string $test_name     Name of test or other label.
 226           *    @access public
 227           */
 228          function paintMethodEnd($test_name) {
 229              $this->_scorer->paintMethodEnd($test_name);
 230          }
 231          
 232          /**
 233           *    Chains to the wrapped reporter.
 234           *    @param string $message        Message is ignored.
 235           *    @access public
 236           */
 237          function paintPass($message) {
 238              $this->_scorer->paintPass($message);
 239          }
 240          
 241          /**
 242           *    Chains to the wrapped reporter.
 243           *    @param string $message        Message is ignored.
 244           *    @access public
 245           */
 246          function paintFail($message) {
 247              $this->_scorer->paintFail($message);
 248          }
 249          
 250          /**
 251           *    Chains to the wrapped reporter.
 252           *    @param string $message    Text of error formatted by
 253           *                              the test case.
 254           *    @access public
 255           */
 256          function paintError($message) {
 257              $this->_scorer->paintError($message);
 258          }
 259          
 260          /**
 261           *    Chains to the wrapped reporter.
 262           *    @param Exception $exception     Object thrown.
 263           *    @access public
 264           */
 265          function paintException($exception) {
 266              $this->_scorer->paintException($exception);
 267          }
 268          
 269          /**
 270           *    Chains to the wrapped reporter.
 271           *    @param string $message        Text to display.
 272           *    @access public
 273           */
 274          function paintMessage($message) {
 275              $this->_scorer->paintMessage($message);
 276          }
 277          
 278          /**
 279           *    Chains to the wrapped reporter.
 280           *    @param string $message        Text to display.
 281           *    @access public
 282           */
 283          function paintFormattedMessage($message) {
 284              $this->_scorer->paintFormattedMessage($message);
 285          }
 286          
 287          /**
 288           *    Chains to the wrapped reporter.
 289           *    @param string $type        Event type as text.
 290           *    @param mixed $payload      Message or object.
 291           *    @return boolean            Should return false if this
 292           *                               type of signal should fail the
 293           *                               test suite.
 294           *    @access public
 295           */
 296          function paintSignal($type, $payload) {
 297              $this->_scorer->paintSignal($type, $payload);
 298          }
 299      }
 300  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7