本文整理汇总了PHP中PHP_Timer::start方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_Timer::start方法的具体用法?PHP PHP_Timer::start怎么用?PHP PHP_Timer::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_Timer
的用法示例。
在下文中一共展示了PHP_Timer::start方法的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: start
/**
* Initializes printing constraints, prints header
* information and starts the test timer
*
* @param Options $options
*/
public function start(Options $options)
{
$this->numTestsWidth = strlen((string) $this->totalCases);
$this->maxColumn = 69 - 2 * $this->numTestsWidth;
printf("\nRunning phpunit in %d process%s with %s%s\n\n", $options->processes, $options->processes > 1 ? 'es' : '', $options->phpunit, $options->functional ? '. Functional mode is on' : '');
if (isset($options->filtered['configuration'])) {
printf("Configuration read from %s\n\n", $options->filtered['configuration']->getPath());
}
$this->timer->start();
$this->colors = $options->colors;
}
示例6: 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();
}
示例7: start
/**
* Initializes printing constraints, prints header
* information and starts the test timer
*
* @param Options $options
*/
public function start(Options $options)
{
$this->numTestsWidth = strlen((string) $this->totalCases);
$this->maxColumn = $this->numberOfColumns + (DIRECTORY_SEPARATOR == "\\" ? -1 : 0) - strlen($this->getProgress());
printf("\nRunning phpunit in %d process%s with %s%s\n\n", $options->processes, $options->processes > 1 ? 'es' : '', $options->phpunit, $options->functional ? '. Functional mode is ON.' : '');
if (isset($options->filtered['configuration'])) {
printf("Configuration read from %s\n\n", $options->filtered['configuration']->getPath());
}
$this->timer->start();
$this->colors = $options->colors;
$this->processSkipped = $this->isSkippedIncompleTestCanBeTracked($options);
}
示例8: 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);
}
示例9: 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;
}
示例10: 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());
}
示例11: 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');
}
示例12: 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;
}
示例13: 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)));
}
示例14: 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');
}
示例15: 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;
}