FormPerformanceTestCase.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form\Test;
  11. /**
  12. * Base class for performance tests.
  13. *
  14. * Copied from Doctrine 2's OrmPerformanceTestCase.
  15. *
  16. * @author robo
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. abstract class FormPerformanceTestCase extends FormIntegrationTestCase
  20. {
  21. /**
  22. * @var int
  23. */
  24. protected $maxRunningTime = 0;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function runTest()
  29. {
  30. $s = microtime(true);
  31. parent::runTest();
  32. $time = microtime(true) - $s;
  33. if (0 != $this->maxRunningTime && $time > $this->maxRunningTime) {
  34. $this->fail(sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
  35. }
  36. }
  37. /**
  38. * @param int $maxRunningTime
  39. *
  40. * @throws \InvalidArgumentException
  41. */
  42. public function setMaxRunningTime($maxRunningTime)
  43. {
  44. if (\is_int($maxRunningTime) && $maxRunningTime >= 0) {
  45. $this->maxRunningTime = $maxRunningTime;
  46. } else {
  47. throw new \InvalidArgumentException();
  48. }
  49. }
  50. /**
  51. * @return int
  52. */
  53. public function getMaxRunningTime()
  54. {
  55. return $this->maxRunningTime;
  56. }
  57. }