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

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