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.  * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  *   * Redistributions of source code must retain the above copyright
  15.  *     notice, this list of conditions and the following disclaimer.
  16.  * 
  17.  *   * Redistributions in binary form must reproduce the above copyright
  18.  *     notice, this list of conditions and the following disclaimer in
  19.  *     the documentation and/or other materials provided with the
  20.  *     distribution.
  21.  *
  22.  *   * Neither the name of Sebastian Bergmann nor the names of his
  23.  *     contributors may be used to endorse or promote products derived
  24.  *     from this software without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37.  * POSSIBILITY OF SUCH DAMAGE.
  38.  *
  39.  * @category   Testing
  40.  * @package    PHPUnit2
  41.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  42.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  43.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  44.  * @version    CVS: $Id: IncludePathTestCollector.php,v 1.13.2.5 2005/12/17 16:04:56 sebastian Exp $
  45.  * @link       http://pear.php.net/package/PHPUnit2
  46.  * @since      File available since Release 2.1.0
  47.  */
  48.  
  49. if (!class_exists('AppendIterator')) {
  50.     class AppendIterator implements Iterator {
  51.         private $iterators;
  52.     
  53.         public function __construct({
  54.             $this->iterators = new ArrayIterator();
  55.         }
  56.     
  57.         public function __call($func$params{
  58.             return call_user_func_array(array($this->getInnerIterator()$func)$params);
  59.         }
  60.  
  61.         public function append(Iterator $it{
  62.             $this->iterators->append($it);
  63.         }
  64.     
  65.         public function getInnerIterator({
  66.             return $this->iterators->current();
  67.         }
  68.     
  69.         public function rewind({
  70.             $this->iterators->rewind();
  71.  
  72.             if ($this->iterators->valid()) {
  73.                 $this->getInnerIterator()->rewind();
  74.             }
  75.         }
  76.         
  77.         public function valid({
  78.             return $this->iterators->valid(&& $this->getInnerIterator()->valid();
  79.         }
  80.         
  81.         public function current({
  82.             return $this->iterators->valid($this->getInnerIterator()->current(: NULL;
  83.         }
  84.         
  85.         public function key({
  86.             return $this->iterators->valid($this->getInnerIterator()->key(: NULL;
  87.         }
  88.         
  89.         public function next({
  90.             if (!$this->iterators->valid()) return;
  91.             $this->getInnerIterator()->next();
  92.  
  93.             if ($this->getInnerIterator()->valid()) return;
  94.             $this->iterators->next();
  95.  
  96.             while ($this->iterators->valid()) {
  97.                 $this->getInnerIterator()->rewind();
  98.  
  99.                 if ($this->getInnerIterator()->valid()) return;
  100.                 $this->iterators->next();
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106. require_once 'PHPUnit2/Runner/TestCollector.php';
  107.  
  108. require_once 'PEAR/Config.php';
  109.  
  110. /**
  111.  * An implementation of a TestCollector that consults the
  112.  * include path set in the php.ini.
  113.  *
  114.  * @category   Testing
  115.  * @package    PHPUnit2
  116.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  117.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  118.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  119.  * @version    Release: @package_version@
  120.  * @link       http://pear.php.net/package/PHPUnit2
  121.  * @since      Class available since Release 2.1.0
  122.  */
  123.  
  124. class PHPUnit2_Runner_IncludePathTestCollector implements PHPUnit2_Runner_TestCollector {
  125.     /**
  126.      * @return array 
  127.      * @access public
  128.      */
  129.     public function collectTests({
  130.         $config   = new PEAR_Config;
  131.         $iterator = new AppendIterator;
  132.         $result   = array();
  133.  
  134.         if (substr(PHP_OS03== 'WIN'{
  135.             $delimiter ';';
  136.         else {
  137.             $delimiter ':';
  138.         }
  139.  
  140.         $paths   explode($delimiterini_get('include_path'));
  141.         $paths[$config->get('test_dir');
  142.  
  143.         foreach ($paths as $path{
  144.             $iterator->append(
  145.               new RecursiveIteratorIterator(
  146.                   new RecursiveDirectoryIterator($path)
  147.               )
  148.             );
  149.         }
  150.  
  151.         foreach ($iterator as $path => $file{
  152.             if ($this->isTestClass($file)) {
  153.                 if (substr(PHP_OS03== 'WIN'{
  154.                     $path str_replace('/''\\'$path);
  155.                 }
  156.  
  157.                 $result[$path;
  158.             }
  159.         }
  160.  
  161.         return $result;
  162.     }
  163.  
  164.     /**
  165.      * Considers a file to contain a test class when it contains the
  166.      * pattern "Test" in its name and its name ends with ".php".
  167.      *
  168.      * @param  string  $classFileName 
  169.      * @return boolean 
  170.      * @access protected
  171.      */
  172.     protected function isTestClass($classFileName{
  173.         return (strpos($classFileName'Test'!== FALSE && substr($classFileName-4== '.php'? TRUE : FALSE;
  174.     }
  175. }
  176.  
  177. /*
  178.  * Local variables:
  179.  * tab-width: 4
  180.  * c-basic-offset: 4
  181.  * c-hanging-comment-ender-p: nil
  182.  * End:
  183.  */
  184. ?>

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