diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php index bacbce882168..0dd044664156 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php @@ -7,6 +7,28 @@ trait InteractsWithTime { + /** + * Freeze time. + * + * @param callable|null $callback + * @return mixed + */ + public function freezeTime($callback = null) + { + return $this->travelTo(Carbon::now(), $callback); + } + + /** + * Freeze time at the beginning of the current second. + * + * @param callable|null $callback + * @return mixed + */ + public function freezeSecond($callback = null) + { + return $this->travelTo(Carbon::now()->startOfSecond(), $callback); + } + /** * Begin travelling to another time. * @@ -30,7 +52,7 @@ public function travelTo($date, $callback = null) Carbon::setTestNow($date); if ($callback) { - return tap($callback(), function () { + return tap($callback(Carbon::now()), function () { Carbon::setTestNow(); }); }