PHPUnit2
[ class tree: PHPUnit2 ] [ index: PHPUnit2 ] [ all elements ]

Source for file IncludePathTestCollector.php

Documentation is available at IncludePathTestCollector.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * PHP Version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   Testing
  14.  * @package    PHPUnit2
  15.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  16.  * @copyright  2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: IncludePathTestCollector.php,v 1.13.2.3 2005/10/12 17:07:07 sebastian Exp $
  19.  * @link       http://pear.php.net/package/PHPUnit2
  20.  * @since      File available since Release 2.1.0
  21.  */
  22.  
  23. if (!class_exists('AppendIterator')) {
  24.     class AppendIterator implements Iterator {
  25.         private $iterators;
  26.     
  27.         public function __construct({
  28.             $this->iterators = new ArrayIterator();
  29.         }
  30.     
  31.         public function __call($func$params{
  32.             return call_user_func_array(array($this->getInnerIterator()$func)$params);
  33.         }
  34.  
  35.         public function append(Iterator $it{
  36.             $this->iterators->append($it);
  37.         }
  38.     
  39.         public function getInnerIterator({
  40.             return $this->iterators->current();
  41.         }
  42.     
  43.         public function rewind({
  44.             $this->iterators->rewind();
  45.  
  46.             if ($this->iterators->valid()) {
  47.                 $this->getInnerIterator()->rewind();
  48.             }
  49.         }
  50.         
  51.         public function valid({
  52.             return $this->iterators->valid(&& $this->getInnerIterator()->valid();
  53.         }
  54.         
  55.         public function current({
  56.             return $this->iterators->valid($this->getInnerIterator()->current(: NULL;
  57.         }
  58.         
  59.         public function key({
  60.             return $this->iterators->valid($this->getInnerIterator()->key(: NULL;
  61.         }
  62.         
  63.         public function next({
  64.             if (!$this->iterators->valid()) return;
  65.             $this->getInnerIterator()->next();
  66.  
  67.             if ($this->getInnerIterator()->valid()) return;
  68.             $this->iterators->next();
  69.  
  70.             while ($this->iterators->valid()) {
  71.                 $this->getInnerIterator()->rewind();
  72.  
  73.                 if ($this->getInnerIterator()->valid()) return;
  74.                 $this->iterators->next();
  75.             }
  76.         }
  77.     }
  78. }
  79.  
  80. require_once 'PHPUnit2/Runner/TestCollector.php';
  81.  
  82. require_once 'PEAR/Config.php';
  83.  
  84. /**
  85.  * An implementation of a TestCollector that consults the
  86.  * include path set in the php.ini.
  87.  *
  88.  * @category   Testing
  89.  * @package    PHPUnit2
  90.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  91.  * @copyright  2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  92.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  93.  * @version    Release: @package_version@
  94.  * @link       http://pear.php.net/package/PHPUnit2
  95.  * @since      Class available since Release 2.1.0
  96.  */
  97.  
  98. class PHPUnit2_Runner_IncludePathTestCollector implements PHPUnit2_Runner_TestCollector {
  99.     /**
  100.      * @return array 
  101.      * @access public
  102.      */
  103.     public function collectTests({
  104.         $config   = new PEAR_Config;
  105.         $iterator = new AppendIterator;
  106.         $result   = array();
  107.  
  108.         if (substr(PHP_OS03== 'WIN'{
  109.             $delimiter ';';
  110.         else {
  111.             $delimiter ':';
  112.         }
  113.  
  114.         $paths   explode($delimiterini_get('include_path'));
  115.         $paths[$config->get('test_dir');
  116.  
  117.         foreach ($paths as $path{
  118.             $iterator->append(
  119.               new RecursiveIteratorIterator(
  120.                   new RecursiveDirectoryIterator($path)
  121.               )
  122.             );
  123.         }
  124.  
  125.         foreach ($iterator as $path => $file{
  126.             if ($this->isTestClass($file)) {
  127.                 if (substr(PHP_OS03== 'WIN'{
  128.                     $path str_replace('/''\\'$path);
  129.                 }
  130.  
  131.                 $result[$path;
  132.             }
  133.         }
  134.  
  135.         return $result;
  136.     }
  137.  
  138.     /**
  139.      * Considers a file to contain a test class when it contains the
  140.      * pattern "Test" in its name and its name ends with ".php".
  141.      *
  142.      * @param  string  $classFileName 
  143.      * @return boolean 
  144.      * @access protected
  145.      */
  146.     protected function isTestClass($classFileName{
  147.         return (strpos($classFileName'Test'!== FALSE && substr($classFileName-4== '.php'? TRUE : FALSE;
  148.     }
  149. }
  150.  
  151. /*
  152.  * Local variables:
  153.  * tab-width: 4
  154.  * c-basic-offset: 4
  155.  * c-hanging-comment-ender-p: nil
  156.  * End:
  157.  */
  158. ?>

Documentation generated on Mon, 11 Mar 2019 14:12:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.