当前位置: 首页>>代码示例>>PHP>>正文


PHP Timer::elapsedTime方法代码示例

本文整理汇总了PHP中Timer::elapsedTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::elapsedTime方法的具体用法?PHP Timer::elapsedTime怎么用?PHP Timer::elapsedTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timer的用法示例。


在下文中一共展示了Timer::elapsedTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: elapsedTimeGreaterThanZeroUsingStartAndStop

 public function elapsedTimeGreaterThanZeroUsingStartAndStop()
 {
     $fixture = new Timer();
     $fixture->start();
     usleep(100 * 1000);
     $fixture->stop();
     $elapsed = $fixture->elapsedTime();
     $this->assertTrue($elapsed > 0.0, 'Elapsed time should be greater than zero');
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:9,代码来源:TimerTest.class.php

示例2: runInternal

 /**
  * Run a test case.
  *
  * @param   unittest.TestCase test
  * @param   unittest.TestResult result
  * @throws  lang.MethodNotImplementedException
  */
 protected function runInternal($test, $result)
 {
     $class = $test->getClass();
     $method = $class->getMethod($test->name);
     $this->notifyListeners('testStarted', array($test));
     // Check for @ignore
     if ($method->hasAnnotation('ignore')) {
         $this->notifyListeners('testNotRun', array($result->set($test, new TestNotRun($test, $method->getAnnotation('ignore')))));
         return;
     }
     // Check for @expect
     $expected = NULL;
     if ($method->hasAnnotation('expect', 'class')) {
         $message = $method->getAnnotation('expect', 'withMessage');
         if ('/' === $message[0]) {
             $pattern = $message;
         } else {
             $pattern = '/' . preg_quote($message, '/') . '/';
         }
         $expected = array(XPClass::forName($method->getAnnotation('expect', 'class')), $pattern);
     } else {
         if ($method->hasAnnotation('expect')) {
             $expected = array(XPClass::forName($method->getAnnotation('expect')), NULL);
         }
     }
     // Check for @limit
     $eta = 0;
     if ($method->hasAnnotation('limit')) {
         $eta = $method->getAnnotation('limit', 'time');
     }
     // Check for @values
     if ($method->hasAnnotation('values')) {
         $annotation = $method->getAnnotation('values');
         $variation = TRUE;
         $values = $this->valuesFor($test, $annotation);
     } else {
         $variation = FALSE;
         $values = array(array());
     }
     // Check for @actions, initialize setUp and tearDown call chains
     $actions = array_merge($this->actionsFor($class, 'unittest.TestAction'), $this->actionsFor($method, 'unittest.TestAction'));
     $setUp = function ($test) use($actions) {
         foreach ($actions as $action) {
             $action->beforeTest($test);
         }
         $test->setUp();
     };
     $tearDown = function ($test) use($actions) {
         $test->tearDown();
         foreach ($actions as $action) {
             $action->afterTest($test);
         }
     };
     $timer = new Timer();
     foreach ($values as $args) {
         $t = $variation ? new TestVariation($test, $args) : $test;
         xp::gc();
         $timer->start();
         // Setup test
         try {
             $setUp($test);
         } catch (PrerequisitesNotMetError $e) {
             $timer->stop();
             $this->notifyListeners('testSkipped', array($result->setSkipped($t, $e, $timer->elapsedTime())));
             xp::gc();
             continue;
         } catch (AssertionFailedError $e) {
             $timer->stop();
             $this->notifyListeners('testFailed', array($result->setFailed($t, $e, $timer->elapsedTime())));
             xp::gc();
             continue;
         } catch (Throwable $x) {
             $timer->stop();
             $this->notifyListeners('testFailed', array($result->set($t, new TestError($t, $x, $timer->elapsedTime()))));
             xp::gc();
             continue;
         }
         // Run test
         try {
             $method->invoke($test, is_array($args) ? $args : array($args));
         } catch (TargetInvocationException $x) {
             $timer->stop();
             $tearDown($test);
             $e = $x->getCause();
             // Was that an expected exception?
             if ($expected && $expected[0]->isInstance($e)) {
                 if ($eta && $timer->elapsedTime() > $eta) {
                     $this->notifyListeners('testFailed', array($result->setFailed($t, new AssertionFailedError('Timeout', sprintf('%.3f', $timer->elapsedTime()), sprintf('%.3f', $eta)), $timer->elapsedTime())));
                 } else {
                     if ($expected[1] && !preg_match($expected[1], $e->getMessage())) {
                         $this->notifyListeners('testFailed', array($result->setFailed($t, new AssertionFailedError('Expected ' . $e->getClassName() . '\'s message differs', $e->getMessage(), $expected[1]), $timer->elapsedTime())));
                     } else {
                         if (sizeof(xp::$errors) > 0) {
//.........这里部分代码省略.........
开发者ID:melogamepay,项目名称:xp-framework,代码行数:101,代码来源:TestSuite.class.php

示例3: runInternal

 /**
  * Run a test case.
  *
  * @param   unittest.TestCase test
  * @param   unittest.TestResult result
  * @throws  lang.MethodNotImplementedException
  */
 protected function runInternal($test, $result)
 {
     $method = $test->getClass()->getMethod($test->name);
     $this->notifyListeners('testStarted', array($test));
     // Check for @ignore
     if ($method->hasAnnotation('ignore')) {
         $this->notifyListeners('testNotRun', array($result->set($test, new TestNotRun($test, $method->getAnnotation('ignore')))));
         return;
     }
     // Check for @expect
     $expected = NULL;
     if ($method->hasAnnotation('expect', 'class')) {
         $message = $method->getAnnotation('expect', 'withMessage');
         if ('/' === $message[0]) {
             $pattern = $message;
         } else {
             $pattern = '/' . preg_quote($message, '/') . '/';
         }
         $expected = array(XPClass::forName($method->getAnnotation('expect', 'class')), $pattern);
     } else {
         if ($method->hasAnnotation('expect')) {
             $expected = array(XPClass::forName($method->getAnnotation('expect')), NULL);
         }
     }
     // Check for @limit
     $eta = 0;
     if ($method->hasAnnotation('limit')) {
         $eta = $method->getAnnotation('limit', 'time');
     }
     xp::gc();
     $timer = new Timer();
     $timer->start();
     // Setup test
     try {
         $test->setUp();
     } catch (PrerequisitesNotMetError $e) {
         $timer->stop();
         $this->notifyListeners('testSkipped', array($result->setSkipped($test, $e, $timer->elapsedTime())));
         xp::gc();
         return;
     } catch (AssertionFailedError $e) {
         $timer->stop();
         $this->notifyListeners('testFailed', array($result->setFailed($test, $e, $timer->elapsedTime())));
         xp::gc();
         return;
     } catch (Throwable $t) {
         $timer->stop();
         $this->notifyListeners('testFailed', array($result->set($test, new TestError($test, $t, $timer->elapsedTime()))));
         xp::gc();
         return;
     }
     // Run test
     try {
         $method->invoke($test, NULL);
     } catch (TargetInvocationException $t) {
         $timer->stop();
         try {
             $test->tearDown();
             $e = $t->getCause();
         } catch (AssertionFailedError $afe) {
             $timer->stop();
             $this->notifyListeners('testFailed', array($result->setFailed($test, $afe, $timer->elapsedTime())));
             xp::gc();
             return;
         } catch (Throwable $t1) {
             $timer->stop();
             $this->notifyListeners('testFailed', array($result->set($test, new TestError($test, $t1, $timer->elapsedTime()))));
             xp::gc();
             return;
         } catch (TargetInvocationException $tie) {
             $cause = $tie->getCause();
             $timer->stop();
             $this->notifyListeners('testFailed', array($result->set($test, new TestError($test, $cause, $timer->elapsedTime()))));
             xp::gc();
             return;
         } catch (Exception $ex) {
             $timer->stop();
             $this->notifyListeners('testFailed', array($result->setFailed($test, new AssertionFailedError($ex->getMessage() . PHP_EOL . $ex->getTraceAsString()), $timer->elapsedTime())));
             xp::gc();
             return;
         }
         $e = $t->getCause();
         // Was that an expected exception?
         if ($expected && $expected[0]->isInstance($e)) {
             if ($eta && $timer->elapsedTime() > $eta) {
                 $this->notifyListeners('testFailed', array($result->setFailed($test, new AssertionFailedError('Timeout', sprintf('%.3f', $timer->elapsedTime()), sprintf('%.3f', $eta)), $timer->elapsedTime())));
             } else {
                 if ($expected[1] && !preg_match($expected[1], $e->getMessage())) {
                     $this->notifyListeners('testFailed', array($result->setFailed($test, new AssertionFailedError('Expected ' . $e->getClassName() . '\'s message differs', $e->getMessage(), $expected[1]), $timer->elapsedTime())));
                 } else {
                     if (sizeof(xp::$errors) > 0) {
                         $this->notifyListeners('testWarning', array($result->set($test, new TestWarning($test, $this->formatErrors(xp::$errors), $timer->elapsedTime()))));
                     } else {
//.........这里部分代码省略.........
开发者ID:Gamepay,项目名称:xp-framework,代码行数:101,代码来源:TestSuite.class.php


注:本文中的Timer::elapsedTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。