home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / RepeatedTest.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.8 KB  |  108 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit                                                        |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2003 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  7. // +------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,        |
  9. // | that is available at http://www.php.net/license/3_0.txt.               |
  10. // | If you did not receive a copy of the PHP license and are unable to     |
  11. // | obtain it through the world-wide-web, please send a note to            |
  12. // | license@php.net so we can mail you a copy immediately.                 |
  13. // +------------------------------------------------------------------------+
  14. //
  15. // $Id: RepeatedTest.php,v 1.4 2003/03/26 18:04:32 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit/TestDecorator.php';
  19.  
  20. /**
  21.  * A Decorator that runs a test repeatedly. 
  22.  *
  23.  * Here is an example:
  24.  *
  25.  *   <?php
  26.  *   require_once 'PHPUnit.php';
  27.  *   require_once 'PHPUnit/RepeatedTest.php';
  28.  *
  29.  *   class MathTest extends PHPUnit_TestCase {
  30.  *     var $fValue1;
  31.  *     var $fValue2;
  32.  *
  33.  *     function MathTest($name) {
  34.  *       $this->PHPUnit_TestCase($name);
  35.  *     }
  36.  *
  37.  *     function setUp() {
  38.  *       $this->fValue1 = 2;
  39.  *       $this->fValue2 = 3;
  40.  *     }
  41.  *
  42.  *     function testAdd() {
  43.  *       $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
  44.  *     }
  45.  *   }
  46.  *
  47.  *   $suite = new PHPUnit_TestSuite;
  48.  *   $suite->addTest(
  49.  *     new PHPUnit_RepeatedTest(
  50.  *       new MathTest('testAdd'),
  51.  *       10
  52.  *     )
  53.  *   );
  54.  *
  55.  *   $result = PHPUnit::run($suite);
  56.  *   echo $result->toString();
  57.  *   ?>
  58.  *
  59.  * @package PHPUnit
  60.  * @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
  61.  *          Based upon JUnit, see http://www.junit.org/ for details.
  62.  */
  63. class PHPUnit_RepeatedTest extends PHPUnit_TestDecorator {
  64.     /**
  65.     * @var    integer
  66.     * @access private
  67.     */
  68.     var $_timesRepeat = 1;
  69.  
  70.     /**
  71.     * Constructor.
  72.     *
  73.     * @param  object
  74.     * @param  integer
  75.     * @access public
  76.     */
  77.     function PHPUnit_RepeatedTest(&$test, $timesRepeat = 1) {
  78.         $this->PHPUnit_TestDecorator($test);
  79.         $this->_timesRepeat = $timesRepeat;
  80.     }
  81.  
  82.     /**
  83.     * Counts the number of test cases that
  84.     * will be run by this test.
  85.     *
  86.     * @return integer
  87.     * @access public
  88.     */
  89.     function countTestCases() {
  90.         return $this->_timesRepeat * $this->_test->countTestCases();
  91.     }
  92.  
  93.     /**
  94.     * Runs the decorated test and collects the
  95.     * result in a TestResult.
  96.     *
  97.     * @param  object
  98.     * @access public
  99.     * @abstract
  100.     */
  101.     function run(&$result) {
  102.         for ($i = 0; $i < $this->_timesRepeat; $i++) {
  103.             $this->_test->run($result);
  104.         }
  105.     }
  106. }
  107. ?>
  108.