FormPerformanceTestCase.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. use Symfony\Component\Form\Tests\VersionAwareTest;
  12. /**
  13. * Base class for performance tests.
  14. *
  15. * Copied from Doctrine 2's OrmPerformanceTestCase.
  16. *
  17. * @author robo
  18. * @author Bernhard Schussek <bschussek@gmail.com>
  19. */
  20. abstract class FormPerformanceTestCase extends FormIntegrationTestCase
  21. {
  22. use VersionAwareTest;
  23. /**
  24. * @var int
  25. */
  26. protected $maxRunningTime = 0;
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function runTest()
  31. {
  32. $s = microtime(true);
  33. parent::runTest();
  34. $time = microtime(true) - $s;
  35. if (0 != $this->maxRunningTime && $time > $this->maxRunningTime) {
  36. $this->fail(sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
  37. }
  38. }
  39. /**
  40. * @throws \InvalidArgumentException
  41. */
  42. public function setMaxRunningTime(int $maxRunningTime)
  43. {
  44. if ($maxRunningTime < 0) {
  45. throw new \InvalidArgumentException();
  46. }
  47. $this->maxRunningTime = $maxRunningTime;
  48. }
  49. /**
  50. * @return int
  51. */
  52. public function getMaxRunningTime()
  53. {
  54. return $this->maxRunningTime;
  55. }
  56. }