OrmPerformanceTestCase.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Doctrine\Tests;
  3. /**
  4. * Description of DoctrinePerformanceTestCase
  5. *
  6. * @author robo
  7. */
  8. class OrmPerformanceTestCase extends OrmFunctionalTestCase
  9. {
  10. /**
  11. * @var integer
  12. */
  13. protected $maxRunningTime = 0;
  14. /**
  15. */
  16. protected function runTest()
  17. {
  18. $s = microtime(true);
  19. parent::runTest();
  20. $time = microtime(true) - $s;
  21. if ($this->maxRunningTime != 0 && $time > $this->maxRunningTime) {
  22. $this->fail(
  23. sprintf(
  24. 'expected running time: <= %s but was: %s',
  25. $this->maxRunningTime,
  26. $time
  27. )
  28. );
  29. }
  30. }
  31. /**
  32. * @param integer $maxRunningTime
  33. * @throws InvalidArgumentException
  34. * @since Method available since Release 2.3.0
  35. */
  36. public function setMaxRunningTime($maxRunningTime)
  37. {
  38. if (is_integer($maxRunningTime) && $maxRunningTime >= 0) {
  39. $this->maxRunningTime = $maxRunningTime;
  40. } else {
  41. throw new \InvalidArgumentException;
  42. }
  43. }
  44. /**
  45. * @return integer
  46. * @since Method available since Release 2.3.0
  47. */
  48. public function getMaxRunningTime()
  49. {
  50. return $this->maxRunningTime;
  51. }
  52. }