This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Form/Test/FormPerformanceTestCase.php

71 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form\Test;
/**
* Base class for performance tests.
*
* Copied from Doctrine 2's OrmPerformanceTestCase.
*
* @author robo
* @author Bernhard Schussek <bschussek@gmail.com>
*/
abstract class FormPerformanceTestCase extends FormIntegrationTestCase
{
/**
2014-04-16 11:30:19 +01:00
* @var int
*/
protected $maxRunningTime = 0;
/**
*/
protected function runTest()
{
$s = microtime(true);
parent::runTest();
$time = microtime(true) - $s;
if ($this->maxRunningTime != 0 && $time > $this->maxRunningTime) {
$this->fail(
sprintf(
'expected running time: <= %s but was: %s',
$this->maxRunningTime,
$time
)
);
}
}
/**
* @param int $maxRunningTime
* @throws \InvalidArgumentException
*/
public function setMaxRunningTime($maxRunningTime)
{
if (is_integer($maxRunningTime) && $maxRunningTime >= 0) {
$this->maxRunningTime = $maxRunningTime;
} else {
2014-02-11 07:51:18 +00:00
throw new \InvalidArgumentException();
}
}
/**
2014-04-16 11:30:19 +01:00
* @return int
* @since Method available since Release 2.3.0
*/
public function getMaxRunningTime()
{
return $this->maxRunningTime;
}
}