home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / tasks / ext / phpunit / PHPUnitTestRunner.php < prev    next >
Encoding:
PHP Script  |  2007-10-31  |  3.3 KB  |  132 lines

  1. <?php
  2. /**
  3.  * $Id: PHPUnitTestRunner.php 276 2007-10-31 08:37:18Z mrook $
  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/tasks/ext/coverage/CoverageMerger.php';
  23.  
  24. require_once 'phing/system/util/Timer.php';
  25.  
  26. /**
  27.  * Simple Testrunner for PHPUnit2/3 that runs all tests of a testsuite.
  28.  *
  29.  * @author Michiel Rook <michiel.rook@gmail.com>
  30.  * @version $Id: PHPUnitTestRunner.php 276 2007-10-31 08:37:18Z mrook $
  31.  * @package phing.tasks.ext.phpunit
  32.  * @since 2.1.0
  33.  */
  34. class PHPUnitTestRunner
  35. {
  36.     const SUCCESS = 0;
  37.     const FAILURES = 1;
  38.     const ERRORS = 2;
  39.  
  40.     private $test = NULL;
  41.     private $suite = NULL;
  42.     private $retCode = 0;
  43.     private $formatters = array();
  44.     
  45.     private $codecoverage = false;
  46.     
  47.     private $project = NULL;
  48.  
  49.     private $groups = array();
  50.     private $excludeGroups = array();
  51.  
  52.     function __construct($suite, Project $project, $groups = array(), $excludeGroups = array())
  53.     {
  54.         $this->suite = $suite;
  55.         $this->project = $project;
  56.         $this->groups = $groups;
  57.         $this->excludeGroups = $excludeGroups;
  58.         $this->retCode = self::SUCCESS;
  59.     }
  60.     
  61.     function setCodecoverage($codecoverage)
  62.     {
  63.         $this->codecoverage = $codecoverage;
  64.     }
  65.  
  66.     function addFormatter($formatter)
  67.     {
  68.         $this->formatters[] = $formatter;
  69.     }
  70.  
  71.     function run()
  72.     {
  73.         $res = NULL;
  74.         
  75.         if (PHPUnitUtil::$installedVersion == 3)
  76.         {
  77.             require_once 'PHPUnit/Framework/TestSuite.php';            
  78.             $res = new PHPUnit_Framework_TestResult();
  79.         }
  80.         else
  81.         {
  82.             require_once 'PHPUnit2/Framework/TestSuite.php';
  83.             $res = new PHPUnit2_Framework_TestResult();
  84.         }
  85.  
  86.         if ($this->codecoverage)
  87.         {
  88.             $res->collectCodeCoverageInformation(TRUE);
  89.         }
  90.  
  91.         foreach ($this->formatters as $formatter)
  92.         {
  93.             $res->addListener($formatter);
  94.         }
  95.  
  96.         $this->suite->run($res, false, $this->groups, $this->excludeGroups);
  97.         
  98.         if ($this->codecoverage)
  99.         {
  100.             $coverageInformation = $res->getCodeCoverageInformation();
  101.             
  102.             if (PHPUnitUtil::$installedVersion == 3)
  103.             {
  104.                 foreach ($coverageInformation as $coverage_info)
  105.                 {
  106.                     CoverageMerger::merge($this->project, array($coverage_info['files']));
  107.                 }
  108.             }
  109.             else
  110.             {
  111.                 CoverageMerger::merge($this->project, $coverageInformation);
  112.             }
  113.         }
  114.         
  115.         if ($res->errorCount() != 0)
  116.         {
  117.             $this->retCode = self::ERRORS;
  118.         }
  119.  
  120.         else if ($res->failureCount() != 0 || $res->notImplementedCount() != 0 || $res->skippedCount() != 0)
  121.         {
  122.             $this->retCode = self::FAILURES;
  123.         }
  124.     }
  125.  
  126.     function getRetCode()
  127.     {
  128.         return $this->retCode;
  129.     }
  130. }
  131. ?>
  132.