| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /** 3 * $Id: BatchTest.php 3076 2006-12-18 08:52:12Z fabien $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://phing.info>. 20 */ 21 22 require_once 'phing/types/FileSet.php'; 23 24 /** 25 * Scans a list of (.php) files given by the fileset attribute, extracts 26 * all subclasses of PHPUnit2_Framework_TestCase. 27 * 28 * @author Michiel Rook <michiel.rook@gmail.com> 29 * @version $Id: BatchTest.php 3076 2006-12-18 08:52:12Z fabien $ 30 * @package phing.tasks.ext.phpunit2 31 * @since 2.1.0 32 */ 33 class BatchTest 34 { 35 /** the list of filesets containing the testcase filename rules */ 36 private $filesets = array(); 37 38 /** the reference to the project */ 39 private $project = NULL; 40 41 /** the classpath to use with Phing::__import() calls */ 42 private $classpath = NULL; 43 44 /** names of classes to exclude */ 45 private $excludeClasses = array(); 46 47 /** 48 * Create a new batchtest instance 49 * 50 * @param Project the project it depends on. 51 */ 52 function __construct(Project $project) 53 { 54 $this->project = $project; 55 } 56 57 /** 58 * Sets the classes to exclude 59 */ 60 function setExclude($exclude) 61 { 62 $this->excludeClasses = explode(" ", $exclude); 63 } 64 65 /** 66 * Sets the classpath 67 */ 68 function setClasspath(Path $classpath) 69 { 70 if ($this->classpath === null) 71 { 72 $this->classpath = $classpath; 73 } 74 else 75 { 76 $this->classpath->append($classpath); 77 } 78 } 79 80 /** 81 * Creates a new Path object 82 */ 83 function createClasspath() 84 { 85 $this->classpath = new Path(); 86 return $this->classpath; 87 } 88 89 /** 90 * Returns the classpath 91 */ 92 function getClasspath() 93 { 94 return $this->classpath; 95 } 96 97 /** 98 * Add a new fileset containing the XML results to aggregate 99 * 100 * @param FileSet the new fileset containing XML results. 101 */ 102 function addFileSet(FileSet $fileset) 103 { 104 $this->filesets[] = $fileset; 105 } 106 107 /** 108 * Iterate over all filesets and return the filename of all files 109 * that end with .php. 110 * 111 * @return array an array of filenames 112 */ 113 private function getFilenames() 114 { 115 $filenames = array(); 116 117 foreach ($this->filesets as $fileset) 118 { 119 $ds = $fileset->getDirectoryScanner($this->project); 120 $ds->scan(); 121 122 $files = $ds->getIncludedFiles(); 123 124 foreach ($files as $file) 125 { 126 if (strstr($file, ".php")) 127 { 128 $filenames[] = $ds->getBaseDir() . "/" . $file; 129 } 130 } 131 } 132 133 return $filenames; 134 } 135 136 /** 137 * Filters an array of classes, removes all classes that are not subclasses of PHPUnit2_Framework_TestCase, 138 * or classes that are declared abstract 139 */ 140 private function filterTests($input) 141 { 142 $reflect = new ReflectionClass($input); 143 144 return is_subclass_of($input, 'PHPUnit2_Framework_TestCase') && (!$reflect->isAbstract()); 145 } 146 147 /** 148 * Returns an array of PHPUnit2_Framework_TestCase classes that are declared 149 * by the files included by the filesets 150 * 151 * @return array an array of PHPUnit2_Framework_TestCase classes. 152 */ 153 function elements() 154 { 155 $filenames = $this->getFilenames(); 156 157 $declaredClasses = array(); 158 159 foreach ($filenames as $filename) 160 { 161 $definedClasses = PHPUnit2Util::getDefinedClasses($filename, $this->classpath); 162 163 $declaredClasses = array_merge($declaredClasses, $definedClasses); 164 } 165 166 $elements = array_filter($declaredClasses, array($this, "filterTests")); 167 168 return $elements; 169 } 170 } 171 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |