diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php index d6413a528062..184a2441ce86 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTime.php @@ -44,8 +44,6 @@ public function travelTo(DateTimeInterface $date, $callback = null) */ public function travelBack() { - Carbon::setTestNow(); - - return Carbon::now(); + return Wormhole::back(); } } diff --git a/src/Illuminate/Foundation/Testing/Wormhole.php b/src/Illuminate/Foundation/Testing/Wormhole.php index 59512981e6ad..d660fe026a75 100644 --- a/src/Illuminate/Foundation/Testing/Wormhole.php +++ b/src/Illuminate/Foundation/Testing/Wormhole.php @@ -115,6 +115,18 @@ public function years($callback = null) return $this->handleCallback($callback); } + /** + * Travel back to the current time. + * + * @return \DateTimeInterface + */ + public static function back() + { + Carbon::setTestNow(); + + return Carbon::now(); + } + /** * Handle the given optional execution callback. * diff --git a/tests/Foundation/Testing/WormholeTest.php b/tests/Foundation/Testing/WormholeTest.php new file mode 100644 index 000000000000..baf41f059132 --- /dev/null +++ b/tests/Foundation/Testing/WormholeTest.php @@ -0,0 +1,25 @@ +addDays(10); + + // Travel in time.. + (new Wormhole(10))->days(); + + // Assert we are now in the future.. + $this->assertEquals($future->format('Y-m-d'), now()->format('Y-m-d')); + + // Assert we can go back to the present.. + $this->assertEquals($present->format('Y-m-d'), Wormhole::back()->format('Y-m-d')); + } +}