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 / phpunit2 / PHPUnit2TestRunner.php < prev    next >
Encoding:
PHP Script  |  2007-12-21  |  2.7 KB  |  107 lines

  1. <?php
  2. /**
  3.  * $Id: PHPUnit2TestRunner.php 82 2006-07-07 18:15:35Z 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 'PHPUnit2/Framework/TestListener.php';
  23. require_once 'PHPUnit2/Framework/TestResult.php';
  24. require_once 'PHPUnit2/Framework/TestSuite.php';
  25.  
  26. require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
  27.  
  28. require_once 'phing/system/util/Timer.php';
  29.  
  30. /**
  31.  * Simple Testrunner for PHPUnit2 that runs all tests of a testsuite.
  32.  *
  33.  * @author Michiel Rook <michiel.rook@gmail.com>
  34.  * @version $Id: PHPUnit2TestRunner.php 82 2006-07-07 18:15:35Z mrook $
  35.  * @package phing.tasks.ext.phpunit2
  36.  * @since 2.1.0
  37.  */
  38. class PHPUnit2TestRunner
  39. {
  40.     const SUCCESS = 0;
  41.     const FAILURES = 1;
  42.     const ERRORS = 2;
  43.  
  44.     private $test = NULL;
  45.     private $suite = NULL;
  46.     private $retCode = 0;
  47.     private $formatters = array();
  48.     
  49.     private $codecoverage = false;
  50.     
  51.     private $project = NULL;
  52.  
  53.     function __construct(PHPUnit2_Framework_TestSuite $suite, Project $project)
  54.     {
  55.         $this->suite = $suite;
  56.         $this->project = $project;
  57.         $this->retCode = self::SUCCESS;
  58.     }
  59.     
  60.     function setCodecoverage($codecoverage)
  61.     {
  62.         $this->codecoverage = $codecoverage;
  63.     }
  64.  
  65.     function addFormatter(PHPUnit2_Framework_TestListener $formatter)
  66.     {
  67.         $this->formatters[] = $formatter;
  68.     }
  69.  
  70.     function run()
  71.     {
  72.         $res = new PHPUnit2_Framework_TestResult();
  73.  
  74.         if ($this->codecoverage)
  75.         {
  76.             $res->collectCodeCoverageInformation(TRUE);
  77.         }
  78.  
  79.         foreach ($this->formatters as $formatter)
  80.         {
  81.             $res->addListener($formatter);
  82.         }
  83.  
  84.         $this->suite->run($res);
  85.         
  86.         if ($this->codecoverage)
  87.         {
  88.             CoverageMerger::merge($this->project, $res->getCodeCoverageInformation());
  89.         }
  90.         
  91.         if ($res->errorCount() != 0)
  92.         {
  93.             $this->retCode = self::ERRORS;
  94.         }
  95.  
  96.         else if ($res->failureCount() != 0 || $res->notImplementedCount() != 0)
  97.         {
  98.             $this->retCode = self::FAILURES;
  99.         }
  100.     }
  101.  
  102.     function getRetCode()
  103.     {
  104.         return $this->retCode;
  105.     }
  106. }
  107. ?>