本文整理汇总了PHP中PHP_Timer::stop方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_Timer::stop方法的具体用法?PHP PHP_Timer::stop怎么用?PHP PHP_Timer::stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_Timer
的用法示例。
在下文中一共展示了PHP_Timer::stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run(\PHPUnit_Framework_TestResult $result = null)
{
if (!$result) {
$result = new \PHPUnit_Framework_TestResult();
}
$opt = null;
\PHP_Timer::start();
$result->startTest($this);
try {
$opt = \Docopt::handle($this->doc, array('argv' => $this->argv, 'exit' => false));
} catch (\Exception $ex) {
// gulp
}
$found = null;
if ($opt) {
if (!$opt->success) {
$found = array('user-error');
} elseif (empty($opt->args)) {
$found = array();
} else {
$found = $opt->args;
}
}
$time = \PHP_Timer::stop();
try {
\PHPUnit_Framework_Assert::assertEquals($this->expect, $found);
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$result->addFailure($this, $e, $time);
}
$result->endTest($this, $time);
return $result;
}
示例2: run
public function run(\PHPUnit_Framework_TestResult $result = null)
{
if (!$result) {
$result = new \PHPUnit_Framework_TestResult();
}
$reader = new \Fulfil\Test\SpecTest\Reader();
$tests = $reader->read($testFile);
foreach ($tests as $test) {
foreach ($test->data as $case) {
\PHP_Timer::start();
$result->startTest($this);
try {
$ctx = new \Fulfil\Context();
$test->test->apply($case->in, $ctx);
$flat = $ctx->flatten();
} catch (\Exception $ex) {
// yum
}
$time = \PHP_Timer::stop();
try {
\PHPUnit_Framework_Assert::assertEquals($case->valid, $flat->valid);
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$result->addFailure($this, $e, $time);
}
$result->endTest($this, $time);
}
}
return $result;
}
示例3: __invoke
/**
* Example middleware invokable class.
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function __invoke(Request $request, Response $response, callable $next)
{
// Start the timer at the beginning of the request
\PHP_Timer::start();
$response = $next($request, $response);
// Log the results
$this->logger->info($request->getUri()->getAuthority() . ' ' . $request->getHeaderLine('AUTH_PRINCIPAL') . ' ' . $request->getAttribute('ip_address') . ' ' . $request->getMethod() . ' ' . $request->getUri()->getPath() . ' ' . $response->getStatusCode() . ' ' . $request->getBody()->getSize() . ' ' . $response->getBody()->getSize() . ' ' . \PHP_Timer::stop());
return $response;
}
示例4: testArrays
public function testArrays()
{
$total = 1000000;
$try1 = array_fill(0, $total, 1);
$try1[rand(0, count($try1) - 1)] = null;
$try2 = array_fill(0, $total, 1);
$try2[rand(0, count($try1) - 1)] = null;
$try2[(string) count($try2)] = 'value';
$uk = rand(0, $total);
unset($try2[$uk]);
print 'isSequentialFastest:' . PHP_EOL;
\PHP_Timer::start();
$isHashFalse = !ArrayStructure::isSequentialFastest($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isHashTrue = !ArrayStructure::isSequentialFastest($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isHashFalse);
$this->assertTrue($isHashTrue);
print 'isSequentialSimple:' . PHP_EOL;
\PHP_Timer::start();
$isSeqFalse = !ArrayStructure::isSequentialSimple($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isSeqTrue = !ArrayStructure::isSequentialSimple($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isSeqFalse);
$this->assertTrue($isSeqTrue);
print 'isSequentialExotic:' . PHP_EOL;
\PHP_Timer::start();
$isSeqTrue = ArrayStructure::isSequentialExotic($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isSeqFalse = ArrayStructure::isSequentialExotic($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isSeqFalse);
$this->assertTrue($isSeqTrue);
print 'isAssoc:' . PHP_EOL;
\PHP_Timer::start();
$isAssocFalse = ArrayStructure::isAssoc($try1);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
\PHP_Timer::start();
$isAssocTrue = ArrayStructure::isAssoc($try2);
$time = \PHP_Timer::stop();
print \PHP_Timer::secondsToTimeString($time) . PHP_EOL;
$this->assertFalse($isAssocFalse);
$this->assertTrue($isAssocTrue);
}
示例5: run
/**
* Run the invocable, and its prerequisites, by calling the invoke method
*
* @param string $start
*/
public function run($start)
{
Timer::start();
$task = $this->buildfile->get($start);
$nodes = $this->buildfile->get($start)->getAdjacencyList();
foreach ($nodes as $prerequisite) {
$this->run($prerequisite);
}
$task->invoke();
$this->duration = Timer::stop();
}
示例6: testRun
/**
* If the dispatcher is run when there is a non-empty queue, a payload will
* be dispatched from that queue.
*/
public function testRun()
{
$dispatcher = new SyncDispatcher($this->queue, $this->worker);
$dispatcher->setWorkerTimeout(1000);
$this->queue->expects($this->any())->method('count')->willReturn(123);
$this->queue->expects($this->once())->method('pop')->willReturn('test');
$this->worker->expects($this->once())->method('run')->with('test');
Timer::start();
$dispatcher->run();
$time = Timer::stop();
$this->assertEquals(1, $time, "Time not within 50ms of target.", 0.05);
}
示例7: testDispatchAction
/**
* When a payload is dispatched, a timeout should occur, after which the
* worker associated with the dispatcher should consume the payload.
*/
public function testDispatchAction()
{
$dispatcher = new DaemonDispatcher($this->queue, $this->worker, 3);
$dispatcher->setManager($this->manager);
$dispatcher->setWorkerTimeout(1000);
$this->worker->expects($this->once())->method('run')->with('testing');
Timer::start();
$dispatcher->getDispatchAction('testing')->__invoke();
$time = Timer::stop();
$this->assertEquals(1, $time, "Time not within 50ms of target.", 0.05);
$this->assertEmpty($dispatcher->getManager()->count());
}
示例8: testPersistentResourceSimulation
public function testPersistentResourceSimulation()
{
PHP_Timer::start();
$movie = new ffmpeg_movie(self::$moviePath, true);
$movie = new ffmpeg_movie(self::$moviePath, true);
$movie = new ffmpeg_movie(self::$moviePath, true);
$elapsed = PHP_Timer::stop();
PHP_Timer::start();
$movie = new ffmpeg_movie(self::$moviePath);
$movie = new ffmpeg_movie(self::$moviePath);
$movie = new ffmpeg_movie(self::$moviePath);
$elapsed1 = PHP_Timer::stop();
$this->assertGreaterThan($elapsed, $elapsed1, 'Persistent resource simulation should be faster');
}
示例9: run
public function run(PHPUnit_Framework_TestResult $result = null)
{
PHPUnit_Framework_Assert::resetCount();
if ($result === NULL) {
$result = new PHPUnit_Framework_TestResult();
}
$this->suite->publishTestArticles();
// Add articles needed by the tests.
$backend = new ParserTestSuiteBackend();
$result->startTest($this);
// Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
if (class_exists('PHP_Timer')) {
PHP_Timer::start();
} else {
PHPUnit_Util_Timer::start();
}
$r = false;
try {
# Run the test.
# On failure, the subclassed backend will throw an exception with
# the details.
$pt = new PHPUnitParserTest();
$r = $pt->runTest($this->test['test'], $this->test['input'], $this->test['result'], $this->test['options'], $this->test['config']);
} catch (PHPUnit_Framework_AssertionFailedError $e) {
// PHPUnit_Util_Timer -> PHP_Timer support (see above)
if (class_exists('PHP_Timer')) {
$result->addFailure($this, $e, PHP_Timer::stop());
} else {
$result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
}
} catch (Exception $e) {
// PHPUnit_Util_Timer -> PHP_Timer support (see above)
if (class_exists('PHP_Timer')) {
$result->addFailure($this, $e, PHP_Timer::stop());
} else {
$result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
}
}
// PHPUnit_Util_Timer -> PHP_Timer support (see above)
if (class_exists('PHP_Timer')) {
$result->endTest($this, PHP_Timer::stop());
} else {
$result->endTest($this, PHPUnit_Util_Timer::stop());
}
$backend->recorder->record($this->test['test'], $r);
$this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
return $result;
}
示例10: podlove_validate_image_cache
function podlove_validate_image_cache()
{
set_time_limit(5 * MINUTE_IN_SECONDS);
PHP_Timer::start();
$cache_files = glob(trailingslashit(Image::cache_dir()) . "*" . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . "cache.yml");
foreach ($cache_files as $cache_file) {
$cache = Yaml::parse(file_get_contents($cache_file));
$validator = new HttpHeaderValidator($cache['source'], $cache['etag'], $cache['last-modified']);
$validator->validate();
if ($validator->hasChanged()) {
wp_schedule_single_event(time(), 'podlove_refetch_cached_image', [$cache['source'], $cache['filename']]);
}
}
$time = PHP_Timer::stop();
\Podlove\Log::get()->addInfo(sprintf('Finished validating %d images in %s', count($cache_files), PHP_Timer::secondsToTimeString($time)));
}
示例11: testPersistentResourceSimulation
public function testPersistentResourceSimulation()
{
PHP_Timer::start();
$provider = new FFmpegOutputProvider('ffmpeg', true);
$provider->setMovieFile(self::$moviePath);
$provider->getOutput();
$provider = clone $provider;
$provider->getOutput();
$provider = clone $provider;
$provider->getOutput();
$elapsed = PHP_Timer::stop();
PHP_Timer::start();
$provider = new FFmpegOutputProvider('ffmpeg', false);
$provider->setMovieFile(self::$moviePath);
$provider->getOutput();
$provider = clone $provider;
$provider->getOutput();
$provider = clone $provider;
$provider->getOutput();
$elapsed1 = PHP_Timer::stop();
$this->assertGreaterThan($elapsed, $elapsed1, 'Persistent resource simulation should be faster');
}
示例12: run
/**
* Runs a test and collects its result in a TestResult instance.
* Executes before/after hooks coming from traits.
*
* @param \PHPUnit_Framework_TestResult $result
* @return \PHPUnit_Framework_TestResult
*/
public final function run(\PHPUnit_Framework_TestResult $result = null)
{
$this->testResult = $result;
$result->startTest($this);
foreach ($this->hooks as $hook) {
if (method_exists($this, $hook . 'Start')) {
$this->{$hook . 'Start'}();
}
}
$status = self::STATUS_PENDING;
$time = 0;
$e = null;
if (!$this->ignored) {
\PHP_Timer::start();
try {
$this->test();
$status = self::STATUS_OK;
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$status = self::STATUS_FAIL;
} catch (\PHPUnit_Framework_Exception $e) {
$status = self::STATUS_ERROR;
} catch (\Throwable $e) {
$e = new \PHPUnit_Framework_ExceptionWrapper($e);
$status = self::STATUS_ERROR;
} catch (\Exception $e) {
$e = new \PHPUnit_Framework_ExceptionWrapper($e);
$status = self::STATUS_ERROR;
}
$time = \PHP_Timer::stop();
}
foreach (array_reverse($this->hooks) as $hook) {
if (method_exists($this, $hook . 'End')) {
$this->{$hook . 'End'}($status, $time, $e);
}
}
$result->endTest($this, $time);
return $result;
}
示例13: run
/**
* Runs a test and collects its result in a TestResult instance.
*
* @param PHPUnit_Framework_TestResult $result
* @param array $options
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result = NULL, array $options = array())
{
if (!class_exists('PEAR_RunTest', FALSE)) {
throw new PHPUnit_Framework_Exception('Class PEAR_RunTest not found.');
}
if (isset($GLOBALS['_PEAR_destructor_object_list']) && is_array($GLOBALS['_PEAR_destructor_object_list']) && !empty($GLOBALS['_PEAR_destructor_object_list'])) {
$pearDestructorObjectListCount = count($GLOBALS['_PEAR_destructor_object_list']);
} else {
$pearDestructorObjectListCount = 0;
}
if ($result === NULL) {
$result = new PHPUnit_Framework_TestResult();
}
$coverage = $result->getCollectCodeCoverageInformation();
$options = array_merge($options, $this->options);
if (!isset($options['include_path'])) {
$options['include_path'] = get_include_path();
}
if ($coverage) {
$options['coverage'] = TRUE;
} else {
$options['coverage'] = FALSE;
}
$currentErrorReporting = error_reporting(E_ERROR | E_WARNING | E_PARSE);
$runner = new PEAR_RunTest(new PHPUnit_Extensions_PhptTestCase_Logger(), $options);
if ($coverage) {
$runner->xdebug_loaded = TRUE;
} else {
$runner->xdebug_loaded = FALSE;
}
$result->startTest($this);
PHP_Timer::start();
$buffer = $runner->run($this->filename, $options);
$time = PHP_Timer::stop();
error_reporting($currentErrorReporting);
$base = basename($this->filename);
$path = dirname($this->filename);
$coverageFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.xdebug', $base);
$diffFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.diff', $base);
$expFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.exp', $base);
$logFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.log', $base);
$outFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.out', $base);
$phpFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.php', $base);
if (is_object($buffer) && $buffer instanceof PEAR_Error) {
$result->addError($this, new PHPUnit_Framework_Exception($buffer->getMessage()), $time);
} else {
if ($buffer == 'SKIPPED') {
$result->addFailure($this, new PHPUnit_Framework_SkippedTestError(), 0);
} else {
if ($buffer != 'PASSED') {
$expContent = file_get_contents($expFile);
$outContent = file_get_contents($outFile);
$result->addFailure($this, new PHPUnit_Framework_ComparisonFailure($expContent, $outContent, $expContent, $outContent), $time);
}
}
}
foreach (array($diffFile, $expFile, $logFile, $phpFile, $outFile) as $file) {
if (file_exists($file)) {
unlink($file);
}
}
if ($coverage && file_exists($coverageFile)) {
eval('$coverageData = ' . file_get_contents($coverageFile) . ';');
unset($coverageData[$phpFile]);
$result->getCodeCoverage()->append($coverageData, $this);
unlink($coverageFile);
}
$result->endTest($this, $time);
// Do not invoke PEAR's destructor mechanism for PHP 4
// as it raises an E_STRICT.
if ($pearDestructorObjectListCount == 0) {
unset($GLOBALS['_PEAR_destructor_object_list']);
} else {
$count = count($GLOBALS['_PEAR_destructor_object_list']) - $pearDestructorObjectListCount;
for ($i = 0; $i < $count; $i++) {
array_pop($GLOBALS['_PEAR_destructor_object_list']);
}
}
return $result;
}
示例14: run
/**
* Runs a test and collects its result in a TestResult instance.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result = null)
{
$sections = $this->parse();
$code = $this->render($sections['FILE']);
if ($result === null) {
$result = new PHPUnit_Framework_TestResult();
}
$php = PHPUnit_Util_PHP::factory();
$skip = false;
$time = 0;
$settings = $this->settings;
$result->startTest($this);
if (isset($sections['INI'])) {
$settings = array_merge($settings, $this->parseIniSection($sections['INI']));
}
if (isset($sections['SKIPIF'])) {
$jobResult = $php->runJob($sections['SKIPIF'], $settings);
if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
$message = substr($message[1], 2);
} else {
$message = '';
}
$result->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
$skip = true;
}
}
if (!$skip) {
PHP_Timer::start();
$jobResult = $php->runJob($code, $settings);
$time = PHP_Timer::stop();
if (isset($sections['EXPECT'])) {
$assertion = 'assertEquals';
$expected = $sections['EXPECT'];
} else {
$assertion = 'assertStringMatchesFormat';
$expected = $sections['EXPECTF'];
}
$output = preg_replace('/\\r\\n/', "\n", trim($jobResult['stdout']));
$expected = preg_replace('/\\r\\n/', "\n", trim($expected));
try {
PHPUnit_Framework_Assert::$assertion($expected, $output);
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$result->addFailure($this, $e, $time);
} catch (Throwable $t) {
$result->addError($this, $t, $time);
} catch (Exception $e) {
$result->addError($this, $e, $time);
}
}
$result->endTest($this, $time);
return $result;
}
示例15: run
/**
* Runs a TestCase.
*
* @param PHPUnit_Framework_Test $test
*/
public function run(PHPUnit_Framework_Test $test)
{
PHPUnit_Framework_Assert::resetCount();
$error = false;
$failure = false;
$incomplete = false;
$risky = false;
$skipped = false;
$this->startTest($test);
$errorHandlerSet = false;
if ($this->convertErrorsToExceptions) {
$oldErrorHandler = set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT);
if ($oldErrorHandler === null) {
$errorHandlerSet = true;
} else {
restore_error_handler();
}
}
$collectCodeCoverage = $this->codeCoverage !== null && !$test instanceof PHPUnit_Extensions_SeleniumTestCase && !$test instanceof PHPUnit_Framework_Warning;
if ($collectCodeCoverage) {
// We need to blacklist test source files when no whitelist is used.
if (!$this->codeCoverage->filter()->hasWhitelist()) {
$classes = $this->getHierarchy(get_class($test), true);
foreach ($classes as $class) {
$this->codeCoverage->filter()->addFileToBlacklist($class->getFileName());
}
}
$this->codeCoverage->start($test);
}
PHP_Timer::start();
try {
if (!$test instanceof PHPUnit_Framework_Warning && $this->beStrictAboutTestSize && extension_loaded('pcntl') && class_exists('PHP_Invoker')) {
switch ($test->getSize()) {
case PHPUnit_Util_Test::SMALL:
$_timeout = $this->timeoutForSmallTests;
break;
case PHPUnit_Util_Test::MEDIUM:
$_timeout = $this->timeoutForMediumTests;
break;
case PHPUnit_Util_Test::LARGE:
$_timeout = $this->timeoutForLargeTests;
break;
}
$invoker = new PHP_Invoker();
$invoker->invoke(array($test, 'runBare'), array(), $_timeout);
} else {
$test->runBare();
}
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$failure = true;
if ($e instanceof PHPUnit_Framework_RiskyTestError) {
$risky = true;
} elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) {
$incomplete = true;
} elseif ($e instanceof PHPUnit_Framework_SkippedTestError) {
$skipped = true;
}
} catch (PHPUnit_Framework_Exception $e) {
$error = true;
} catch (Exception $e) {
$e = new PHPUnit_Framework_ExceptionWrapper($e);
$error = true;
}
$time = PHP_Timer::stop();
$test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
if ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) {
$risky = true;
}
if ($collectCodeCoverage) {
$append = !$risky && !$incomplete && !$skipped;
$linesToBeCovered = array();
$linesToBeUsed = array();
if ($append && $test instanceof PHPUnit_Framework_TestCase) {
$linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName(false));
$linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(get_class($test), $test->getName(false));
}
try {
$this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed);
} catch (PHP_CodeCoverage_Exception_UnintentionallyCoveredCode $cce) {
$this->addFailure($test, new PHPUnit_Framework_UnintentionallyCoveredCodeError('This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage()), $time);
} catch (PHPUnit_Framework_InvalidCoversTargetException $cce) {
$this->addFailure($test, new PHPUnit_Framework_InvalidCoversTargetError($cce->getMessage()), $time);
} catch (PHP_CodeCoverage_Exception $cce) {
$error = true;
if (!isset($e)) {
$e = $cce;
}
}
}
if ($errorHandlerSet === true) {
restore_error_handler();
}
if ($error === true) {
$this->addError($test, $e, $time);
} elseif ($failure === true) {
//.........这里部分代码省略.........