File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/Illuminate/Foundation/Testing Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,30 @@ public function __construct($value)
24
24
$ this ->value = $ value ;
25
25
}
26
26
27
+ /**
28
+ * Travel forward the given number of microseconds.
29
+ *
30
+ * @param callable|null $callback
31
+ * @return mixed
32
+ */
33
+ public function microsecond ($ callback = null )
34
+ {
35
+ return $ this ->microseconds ($ callback );
36
+ }
37
+
38
+ /**
39
+ * Travel forward the given number of microseconds.
40
+ *
41
+ * @param callable|null $callback
42
+ * @return mixed
43
+ */
44
+ public function microseconds ($ callback = null )
45
+ {
46
+ Carbon::setTestNow (Carbon::now ()->addMicroseconds ($ this ->value ));
47
+
48
+ return $ this ->handleCallback ($ callback );
49
+ }
50
+
27
51
/**
28
52
* Travel forward the given number of milliseconds.
29
53
*
Original file line number Diff line number Diff line change @@ -46,4 +46,18 @@ public function testCarbonImmutableCompatibility()
46
46
// Restore the default Date Factory...
47
47
Date::useDefault ();
48
48
}
49
+
50
+ public function testItCanTravelByMicroseconds ()
51
+ {
52
+ Date::use (CarbonImmutable::class);
53
+ Date::setTestNow (Date::parse ('2000-01-01 00:00:00 ' )->startOfSecond ());
54
+
55
+ (new Wormhole (1 ))->microsecond ();
56
+ $ this ->assertSame ('2000-01-01 00:00:00.000001 ' , Date::now ()->format ('Y-m-d H:i:s.u ' ));
57
+
58
+ (new Wormhole (5 ))->microseconds ();
59
+ $ this ->assertSame ('2000-01-01 00:00:00.000006 ' , Date::now ()->format ('Y-m-d H:i:s.u ' ));
60
+
61
+ Date::useDefault ();
62
+ }
49
63
}
You can’t perform that action at this time.
0 commit comments