[ 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/ -> collector.php (source)

   1  <?php
   2  /**
   3   * This file contains the following classes: {@link SimpleCollector}, 
   4   * {@link SimplePatternCollector}.
   5   * 
   6   * @author Travis Swicegood <development@domain51.com>
   7   * @package SimpleTest
   8   * @subpackage UnitTester
   9   * @version $Id: collector.php 1397 2006-09-07 07:55:53Z wei $
  10   */
  11  
  12  /**
  13   * The basic collector for {@link GroupTest}
  14   *
  15   * @see collect(), GroupTest::collect()
  16   * @package SimpleTest
  17   * @subpackage UnitTester
  18   */
  19  class SimpleCollector {
  20      
  21      /**
  22       * Strips off any kind of slash at the end so as to normalise the path
  23       *
  24       * @param string $path    Path to normalise.
  25       */
  26      function _removeTrailingSlash($path) {
  27          return preg_replace('|[\\/]$|', '', $path);
  28          
  29         /**
  30          * @internal
  31          * Try benchmarking the following.  It's more code, but by not using the
  32          * regex, it may be faster?  Also, shouldn't be looking for 
  33          * DIRECTORY_SEPERATOR instead of a manual "/"? 
  34          */
  35          if (substr($path, -1) == DIRECTORY_SEPERATOR) {
  36              return substr($path, 0, -1);
  37          } else {
  38              return $path;
  39          }
  40      }
  41  
  42      /**
  43       * Scans the directory and adds what it can.
  44       * @param object $test    Group test with {@link GroupTest::addTestFile()} method.
  45       * @param string $path    Directory to scan.
  46       * @see _attemptToAdd()
  47       */
  48      function collect($test, $path) {
  49          $path = $this->_removeTrailingSlash($path);
  50          if ($handle = opendir($path)) {
  51              while (($entry = readdir($handle)) !== false) {
  52                  $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry);
  53              }
  54              closedir($handle);
  55          }
  56      }
  57      
  58      /**
  59       * This method determines what should be done with a given file and adds
  60       * it via {@link GroupTest::addTestFile()} if necessary.
  61       *
  62       * This method should be overriden to provide custom matching criteria, 
  63       * such as pattern matching, recursive matching, etc.  For an example, see
  64       * {@link SimplePatternCollector::_handle()}.
  65       *
  66       * @param object $test      Group test with {@link GroupTest::addTestFile()} method.
  67       * @param string $filename  A filename as generated by {@link collect()}
  68       * @see collect()
  69       * @access protected
  70       */
  71      function _handle($test, $file) {
  72          if (!is_dir($file)) {
  73              $test->addTestFile($file);
  74          }
  75      }
  76  }
  77  
  78  /**
  79   * An extension to {@link SimpleCollector} that only adds files matching a
  80   * given pattern.
  81   *
  82   * @package SimpleTest
  83   * @subpackage UnitTester
  84   * @see SimpleCollector
  85   */
  86  class SimplePatternCollector extends SimpleCollector {
  87      protected $_pattern;
  88      
  89      
  90      /**
  91       *
  92       * @param string $pattern   Perl compatible regex to test name against
  93       *  See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE}
  94       *  for full documentation of valid pattern.s
  95       */
  96      function SimplePatternCollector($pattern = '/php$/i') {
  97          $this->_pattern = $pattern;
  98      }
  99      
 100      
 101      /**
 102       * Attempts to add files that match a given pattern.
 103       *
 104       * @see SimpleCollector::_handle()
 105       * @param object $test    Group test with {@link GroupTest::addTestFile()} method.
 106       * @param string $path    Directory to scan.
 107       * @access protected
 108       */
 109      function _handle($test, $filename) {
 110          if (preg_match($this->_pattern, $filename)) {
 111              parent::_handle($test, $filename);
 112          }
 113      }
 114  }
 115  ?>


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