[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/tasks/ext/coverage/ -> CoverageSetupTask.php (source)

   1  <?php
   2  /**
   3   * $Id: CoverageSetupTask.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/Task.php';
  23  require_once 'phing/system/io/PhingFile.php';
  24  require_once 'phing/system/io/Writer.php';
  25  require_once 'phing/system/util/Properties.php';
  26  require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
  27  
  28  /**
  29   * Initializes a code coverage database
  30   *
  31   * @author Michiel Rook <michiel.rook@gmail.com>
  32   * @version $Id: CoverageSetupTask.php 3076 2006-12-18 08:52:12Z fabien $
  33   * @package phing.tasks.ext.coverage
  34   * @since 2.1.0
  35   */
  36  class CoverageSetupTask extends Task
  37  {
  38      /** the list of filesets containing the .php filename rules */
  39      private $filesets = array();
  40  
  41      /** the filename of the coverage database */
  42      private $database = "coverage.db";
  43  
  44      /** the classpath to use (optional) */
  45      private $classpath = NULL;
  46  
  47      /**
  48       * Add a new fileset containing the .php files to process
  49       *
  50       * @param FileSet the new fileset containing .php files
  51       */
  52  	function addFileSet(FileSet $fileset)
  53      {
  54          $this->filesets[] = $fileset;
  55      }
  56  
  57      /**
  58       * Sets the filename of the coverage database to use
  59       *
  60       * @param string the filename of the database
  61       */
  62  	function setDatabase($database)
  63      {
  64          $this->database = $database;
  65      }
  66  
  67  	function setClasspath(Path $classpath)
  68      {
  69          if ($this->classpath === null)
  70          {
  71              $this->classpath = $classpath;
  72          }
  73          else
  74          {
  75              $this->classpath->append($classpath);
  76          }
  77      }
  78  
  79  	function createClasspath()
  80      {
  81          $this->classpath = new Path();
  82          return $this->classpath;
  83      }
  84      
  85      /**
  86       * Iterate over all filesets and return the filename of all files
  87       * that end with .php. This is to avoid loading an xml file
  88       * for example.
  89       *
  90       * @return array an array of (basedir, filenames) pairs
  91       */
  92  	private function getFilenames()
  93      {
  94          $files = array();
  95  
  96          foreach ($this->filesets as $fileset)
  97          {
  98              $ds = $fileset->getDirectoryScanner($this->project);
  99              $ds->scan();
 100  
 101              $includedFiles = $ds->getIncludedFiles();
 102  
 103              foreach ($includedFiles as $file)
 104              {
 105                  if (strstr($file, ".php"))
 106                  {
 107                      $fs = new PhingFile(realpath($ds->getBaseDir()), $file);
 108                      
 109                      $files[] = array('key' => strtolower($fs->getAbsolutePath()), 'fullname' => $fs->getAbsolutePath());
 110                  }
 111              }
 112          }
 113  
 114          return $files;
 115      }
 116      
 117  	function init()
 118      {
 119          include_once 'PHPUnit2/Framework/TestCase.php';
 120          if (!class_exists('PHPUnit2_Framework_TestCase')) {
 121              throw new Exception("PHPUnit2Task depends on PEAR PHPUnit2 package being installed.");
 122          }
 123      }
 124  
 125  	function main()
 126      {
 127          $files = $this->getFilenames();
 128  
 129          $this->log("Setting up coverage database for " . count($files) . " files");
 130  
 131          $props = new Properties();
 132  
 133          foreach ($files as $file)
 134          {
 135              $fullname = $file['fullname'];
 136              $filename = $file['key'];
 137              
 138              $props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
 139          }
 140  
 141          $dbfile = new PhingFile($this->database);
 142  
 143          $props->store($dbfile);
 144  
 145          $this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
 146      
 147          foreach ($files as $file)
 148          {
 149              $fullname = $file['fullname'];
 150              
 151              xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
 152              
 153              Phing::__import($fullname, $this->classpath);
 154              
 155              $coverage = xdebug_get_code_coverage();
 156              
 157              xdebug_stop_code_coverage();
 158              
 159              CoverageMerger::merge($this->project, array($coverage));
 160          }
 161      }
 162  }
 163  ?>


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7