Source for file default_reporter.php

Documentation is available at default_reporter.php

  1. <?php
  2. /**
  3.  *  Optional include file for SimpleTest
  4.  *  @package    SimpleTest
  5.  *  @subpackage UnitTester
  6.  *  @version    $Id: default_reporter.php 1704 2008-03-25 00:47:04Z lastcraft $
  7.  */
  8.  
  9. /**#@+
  10.  *  include other SimpleTest class files
  11.  */
  12. require_once(dirname(__FILE__'/simpletest.php');
  13. require_once(dirname(__FILE__'/scorer.php');
  14. require_once(dirname(__FILE__'/reporter.php');
  15. require_once(dirname(__FILE__'/xml.php');
  16. /**#@-*/
  17.  
  18.  *    Parser for command line arguments. Extracts
  19.  *    the a specific test to run and engages XML
  20.  *    reporting when necessary.
  21.  *    @package SimpleTest
  22.  *    @subpackage UnitTester
  23.  */
  24.     var $_to_property = array(
  25.             'case' => '_case''c' => '_case',
  26.             'test' => '_test''t' => '_test',
  27.             'xml' => '_xml''x' => '_xml');
  28.     var $_case = '';
  29.     var $_test = '';
  30.     var $_xml = false;
  31.     var $_no_skips = false;
  32.     
  33.     /**
  34.      *    Parses raw command line arguments into object properties.
  35.      *    @param string $arguments        Raw commend line arguments.
  36.      */
  37.     function SimpleCommandLineParser($arguments{
  38.         if (is_array($arguments)) {
  39.             return;
  40.         }
  41.         foreach ($arguments as $i => $argument{
  42.             if (preg_match('/^--?(test|case|t|c)=(.+)$/'$argument$matches)) {
  43.                 $property $this->_to_property[$matches[1]];
  44.                 $this->$property $matches[2];
  45.             elseif (preg_match('/^--?(test|case|t|c)$/'$argument$matches)) {
  46.                 $property $this->_to_property[$matches[1]];
  47.                 if (isset($arguments[$i 1])) {
  48.                     $this->$property $arguments[$i 1];
  49.                 }
  50.             elseif (preg_match('/^--?(xml|x)$/'$argument)) {
  51.                 $this->_xml = true;
  52.             elseif (preg_match('/^--?(no-skip|no-skips|s)$/'$argument)) {
  53.                 $this->_no_skips = true;
  54.             }
  55.         }
  56.     }
  57.     
  58.     /**
  59.      *    Run only this test.
  60.      *    @return string        Test name to run.
  61.      *    @access public
  62.      */
  63.     function getTest({
  64.         return $this->_test;
  65.     }
  66.     
  67.     /**
  68.      *    Run only this test suite.
  69.      *    @return string        Test class name to run.
  70.      *    @access public
  71.      */
  72.     function getTestCase({
  73.         return $this->_case;
  74.     }
  75.     
  76.     /**
  77.      *    Output should be XML or not.
  78.      *    @return boolean        True if XML desired.
  79.      *    @access public
  80.      */
  81.     function isXml({
  82.         return $this->_xml;
  83.     }
  84.     
  85.     /**
  86.      *    Output should suppress skip messages.
  87.      *    @return boolean        True for no skips.
  88.      *    @access public
  89.      */
  90.     function noSkips({
  91.         return $this->_no_skips;
  92.     }
  93. }
  94.  
  95. /**
  96.  *    The default reporter used by SimpleTest's autorun
  97.  *    feature. The actual reporters used are dependency
  98.  *    injected and can be overridden.
  99.  *    @package SimpleTest
  100.  *    @subpackage UnitTester
  101.  */
  102.     
  103.     /**
  104.      *  Assembles the appopriate reporter for the environment.
  105.      */
  106.     function DefaultReporter({
  107.         if (SimpleReporter::inCli()) {
  108.             global $argv;
  109.             $parser new SimpleCommandLineParser($argv);
  110.             $interfaces $parser->isXml(array('XmlReporter'array('TextReporter');
  111.             $reporter &new SelectiveReporter(
  112.                     SimpleTest::preferred($interfaces),
  113.                     $parser->getTestCase(),
  114.                     $parser->getTest());
  115.             if ($parser->noSkips()) {
  116.                 $reporter &new NoSkipsReporter($reporter);
  117.             }
  118.         else {
  119.             $reporter &new SelectiveReporter(
  120.                     SimpleTest::preferred('HtmlReporter'),
  121.                     @$_GET['c'],
  122.                     @$_GET['t']);
  123.             if (@$_GET['skips'== 'no' || @$_GET['show-skips'== 'no'{
  124.                 $reporter &new NoSkipsReporter($reporter);
  125.             }
  126.         }
  127.         $this->SimpleReporterDecorator($reporter);
  128.     }
  129. }
  130. ?>

Documentation generated on Sun, 04 May 2008 09:21:25 -0500 by phpDocumentor 1.3.0