PHPUnit2
[ class tree: PHPUnit2 ] [ index: PHPUnit2 ] [ all elements ]

Source for file PerformanceTestCase.php

Documentation is available at PerformanceTestCase.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit2                                                       |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 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: PerformanceTestCase.php,v 1.6.2.2 2005/02/04 10:01:55 sebastian Exp $
  16. //
  17.  
  18. require_once 'Benchmark/Timer.php';
  19. require_once 'PHPUnit2/Framework/TestCase.php';
  20.  
  21. /**
  22.  * A TestCase that expects a TestCase to be executed
  23.  * meeting a given time limit.
  24.  *
  25.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @copyright   Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  28.  * @category    Testing
  29.  * @package     PHPUnit2
  30.  * @subpackage  Extensions
  31.  * @since       2.1.0
  32.  */
  33.     // {{{ Instance Variables
  34.  
  35.     /**
  36.     * @var    double 
  37.     * @access private
  38.     */
  39.     private $maxRunningTime = 0;
  40.  
  41.     // }}}
  42.     // {{{ public function __construct($name, $maxRunningTime = 0)
  43.  
  44.     /**
  45.     * @param  string $name 
  46.     * @param  double $maxRunningTime 
  47.     * @access public
  48.     */
  49.     public function __construct($name$maxRunningTime = 0{
  50.         if (is_numeric($maxRunningTime&&
  51.             $maxRunningTime >= 0{
  52.             $this->maxRunningTime $maxRunningTime;
  53.         else {
  54.             throw new Exception('Illegal argument.');
  55.         }
  56.  
  57.         parent::__construct($name);
  58.     }
  59.  
  60.     // }}}
  61.     // {{{ protected function runTest()
  62.  
  63.     /**
  64.     * @access public
  65.     */
  66.     protected function runTest({
  67.         $timer = new Benchmark_Timer;
  68.  
  69.         $timer->start();
  70.         parent::runTest();
  71.         $timer->stop();
  72.  
  73.         if ($this->maxRunningTime != 0 &&
  74.             $timer->timeElapsed($this->maxRunningTime{
  75.             $this->fail(
  76.               sprintf(
  77.                 'expected running time: <= %s but was: %s',
  78.  
  79.                 $this->maxRunningTime,
  80.                 $timer->timeElapsed()
  81.               )
  82.             );
  83.         }
  84.     }
  85.  
  86.     // }}}
  87. }
  88.  
  89. /*
  90.  * vim600:  et sw=2 ts=2 fdm=marker
  91.  * vim<600: et sw=2 ts=2
  92.  */
  93. ?>

Documentation generated on Mon, 11 Mar 2019 14:19:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.