/** * Runs the expectation. * * @param Closure $closure The closure to run/spin. */ protected function _spin($closure) { if (($timeout = $this->timeout()) < 0) { $closure(); } else { Code::spin($closure, $timeout, true); } }
$closure = function () { Code::spin("invalid", 1); }; expect($closure)->toThrow(new InvalidArgumentException()); }); it("throws an exception on timeout", function () { $start = microtime(true); $closure = function () { Code::spin(function () { }, 1); }; expect($closure)->toThrow(new TimeoutException('Timeout reached, execution aborted after 1 second(s).')); $end = microtime(true); expect($end - $start)->toBeGreaterThan(1); }); it("respects the delay delay", function () { $start = microtime(true); $counter = 0; $closure = function () use(&$counter) { Code::spin(function () use(&$counter) { $counter++; }, 1, 250000); }; expect($closure)->toThrow(new TimeoutException('Timeout reached, execution aborted after 1 second(s).')); expect($counter)->toBeGreaterThan(3); expect($counter)->toBeLessThan(6); $end = microtime(true); expect($end - $start)->toBeGreaterThan(1); }); }); });