diff --git a/src/Illuminate/Foundation/Testing/Wormhole.php b/src/Illuminate/Foundation/Testing/Wormhole.php index ef02e5a26f03..d660fe026a75 100644 --- a/src/Illuminate/Foundation/Testing/Wormhole.php +++ b/src/Illuminate/Foundation/Testing/Wormhole.php @@ -2,7 +2,7 @@ namespace Illuminate\Foundation\Testing; -use Illuminate\Support\Facades\Date; +use Illuminate\Support\Carbon; class Wormhole { @@ -32,7 +32,7 @@ public function __construct($value) */ public function milliseconds($callback = null) { - Date::setTestNow(Date::now()->addMilliseconds($this->value)); + Carbon::setTestNow(Carbon::now()->addMilliseconds($this->value)); return $this->handleCallback($callback); } @@ -45,7 +45,7 @@ public function milliseconds($callback = null) */ public function seconds($callback = null) { - Date::setTestNow(Date::now()->addSeconds($this->value)); + Carbon::setTestNow(Carbon::now()->addSeconds($this->value)); return $this->handleCallback($callback); } @@ -58,7 +58,7 @@ public function seconds($callback = null) */ public function minutes($callback = null) { - Date::setTestNow(Date::now()->addMinutes($this->value)); + Carbon::setTestNow(Carbon::now()->addMinutes($this->value)); return $this->handleCallback($callback); } @@ -71,7 +71,7 @@ public function minutes($callback = null) */ public function hours($callback = null) { - Date::setTestNow(Date::now()->addHours($this->value)); + Carbon::setTestNow(Carbon::now()->addHours($this->value)); return $this->handleCallback($callback); } @@ -84,7 +84,7 @@ public function hours($callback = null) */ public function days($callback = null) { - Date::setTestNow(Date::now()->addDays($this->value)); + Carbon::setTestNow(Carbon::now()->addDays($this->value)); return $this->handleCallback($callback); } @@ -97,7 +97,7 @@ public function days($callback = null) */ public function weeks($callback = null) { - Date::setTestNow(Date::now()->addWeeks($this->value)); + Carbon::setTestNow(Carbon::now()->addWeeks($this->value)); return $this->handleCallback($callback); } @@ -110,7 +110,7 @@ public function weeks($callback = null) */ public function years($callback = null) { - Date::setTestNow(Date::now()->addYears($this->value)); + Carbon::setTestNow(Carbon::now()->addYears($this->value)); return $this->handleCallback($callback); } @@ -122,9 +122,9 @@ public function years($callback = null) */ public static function back() { - Date::setTestNow(); + Carbon::setTestNow(); - return Date::now(); + return Carbon::now(); } /** @@ -137,7 +137,7 @@ protected function handleCallback($callback) { if ($callback) { return tap($callback(), function () { - Date::setTestNow(); + Carbon::setTestNow(); }); } } diff --git a/src/Illuminate/Support/Carbon.php b/src/Illuminate/Support/Carbon.php index 9383c3fd897d..004b27b0751e 100644 --- a/src/Illuminate/Support/Carbon.php +++ b/src/Illuminate/Support/Carbon.php @@ -3,8 +3,16 @@ namespace Illuminate\Support; use Carbon\Carbon as BaseCarbon; +use Carbon\CarbonImmutable as BaseCarbonImmutable; class Carbon extends BaseCarbon { - // + /** + * {@inheritdoc} + */ + public static function setTestNow($testNow = null) + { + BaseCarbon::setTestNow($testNow); + BaseCarbonImmutable::setTestNow($testNow); + } } diff --git a/tests/Support/SupportCarbonTest.php b/tests/Support/SupportCarbonTest.php index ea4a53bfff91..cdd865b8b470 100644 --- a/tests/Support/SupportCarbonTest.php +++ b/tests/Support/SupportCarbonTest.php @@ -4,6 +4,7 @@ use BadMethodCallException; use Carbon\Carbon as BaseCarbon; +use Carbon\CarbonImmutable as BaseCarbonImmutable; use DateTime; use DateTimeInterface; use Illuminate\Support\Carbon; @@ -108,4 +109,13 @@ public function testDeserializationOccursCorrectly() $this->assertInstanceOf(Carbon::class, $deserialized); } + + public function testSetTestNowWillPersistBetweenImmutableAndMutableInstance() + { + Carbon::setTestNow(new Carbon('2017-06-27 13:14:15.000000')); + + $this->assertSame('2017-06-27 13:14:15', Carbon::now()->toDateTimeString()); + $this->assertSame('2017-06-27 13:14:15', BaseCarbon::now()->toDateTimeString()); + $this->assertSame('2017-06-27 13:14:15', BaseCarbonImmutable::now()->toDateTimeString()); + } }