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 / PHPUnit2 / Extensions / RepeatedTest.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  4.5 KB  |  139 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * PHP Version 5
  6.  *
  7.  * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  *   * Redistributions of source code must retain the above copyright
  15.  *     notice, this list of conditions and the following disclaimer.
  16.  * 
  17.  *   * Redistributions in binary form must reproduce the above copyright
  18.  *     notice, this list of conditions and the following disclaimer in
  19.  *     the documentation and/or other materials provided with the
  20.  *     distribution.
  21.  *
  22.  *   * Neither the name of Sebastian Bergmann nor the names of his
  23.  *     contributors may be used to endorse or promote products derived
  24.  *     from this software without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37.  * POSSIBILITY OF SUCH DAMAGE.
  38.  *
  39.  * @category   Testing
  40.  * @package    PHPUnit2
  41.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  42.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  43.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  44.  * @version    CVS: $Id: RepeatedTest.php,v 1.15.2.4 2005/12/17 16:04:56 sebastian Exp $
  45.  * @link       http://pear.php.net/package/PHPUnit2
  46.  * @since      File available since Release 2.0.0
  47.  */
  48.  
  49. require_once 'PHPUnit2/Extensions/TestDecorator.php';
  50.  
  51. /**
  52.  * A Decorator that runs a test repeatedly.
  53.  *
  54.  * @category   Testing
  55.  * @package    PHPUnit2
  56.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  57.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  58.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  59.  * @version    Release: 2.3.6
  60.  * @link       http://pear.php.net/package/PHPUnit2
  61.  * @since      Class available since Release 2.0.0
  62.  */
  63. class PHPUnit2_Extensions_RepeatedTest extends PHPUnit2_Extensions_TestDecorator {
  64.     /**
  65.      * @var    integer
  66.      * @access private
  67.      */
  68.     private $timesRepeat = 1;
  69.  
  70.     /**
  71.      * Constructor.
  72.      *
  73.      * @param  PHPUnit2_Framework_Test $test
  74.      * @param  integer                 $timesRepeat
  75.      * @throws Exception
  76.      * @access public
  77.      */
  78.     public function __construct(PHPUnit2_Framework_Test $test, $timesRepeat = 1) {
  79.         parent::__construct($test);
  80.  
  81.         if (is_integer($timesRepeat) &&
  82.             $timesRepeat >= 0) {
  83.             $this->timesRepeat = $timesRepeat;
  84.         } else {
  85.             throw new Exception(
  86.               'Argument 2 must be a positive integer.'
  87.             );
  88.         }
  89.     }
  90.  
  91.     /**
  92.      * Counts the number of test cases that
  93.      * will be run by this test.
  94.      *
  95.      * @return integer
  96.      * @access public
  97.      */
  98.     public function countTestCases() {
  99.         return $this->timesRepeat * $this->test->countTestCases();
  100.     }
  101.  
  102.     /**
  103.      * Runs the decorated test and collects the
  104.      * result in a TestResult.
  105.      *
  106.      * @param  PHPUnit2_Framework_TestResult $result
  107.      * @return PHPUnit2_Framework_TestResult
  108.      * @throws Exception
  109.      * @access public
  110.      */
  111.     public function run($result = NULL) {
  112.         if ($result === NULL) {
  113.             $result = $this->createResult();
  114.         }
  115.  
  116.         // XXX: Workaround for missing ability to declare type-hinted parameters as optional.
  117.         else if (!($result instanceof PHPUnit2_Framework_TestResult)) {
  118.             throw new Exception(
  119.               'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.'
  120.             );
  121.         }
  122.  
  123.         for ($i = 0; $i < $this->timesRepeat && !$result->shouldStop(); $i++) {
  124.             $this->test->run($result);
  125.         }
  126.  
  127.         return $result;
  128.     }
  129. }
  130.  
  131. /*
  132.  * Local variables:
  133.  * tab-width: 4
  134.  * c-basic-offset: 4
  135.  * c-hanging-comment-ender-p: nil
  136.  * End:
  137.  */
  138. ?>
  139.