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

Source for file IncludePathTestCollector.php

Documentation is available at IncludePathTestCollector.php

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

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