diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php index 4e8c8fcef59e31f495312f4774da9e8d71b864a1..89a98a45ed75f77f80e07007e5119706b5561f4d 100644 --- a/_test/core/DokuWikiTest.php +++ b/_test/core/DokuWikiTest.php @@ -156,4 +156,26 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { return $this->getMock($originalClassName, $methods); } } + + /** + * Waits until a new second has passed + * + * The very first call will return immeadiately, proceeding calls will return + * only after at least 1 second after the last call has passed. + * + * When passing $init=true it will not return immeadiately but use the current + * second as initialization. It might still return faster than a second. + * + * @param bool $init wait from now on, not from last time + * @return int new timestamp + */ + protected function waitForTick($init = false) { + static $last = 0; + if($init) $last = time(); + while($last === $now = time()) { + usleep(100000); //recheck in a 10th of a second + } + $last = $now; + return $now; + } }