diff --git a/helpers.md b/helpers.md index e48d891d14f..fc0fbfa3922 100644 --- a/helpers.md +++ b/helpers.md @@ -2414,4 +2414,16 @@ Sleep::whenFakingSleep(function (Duration $duration) { }); ``` +As progressing time is a common requirement, the `fake` method accepts a `syncWithCarbon` argument to keep Carbon in sync when sleeping within a test: + +```php +Sleep::fake(syncWithCarbon: true); + +$start = now(); + +Sleep::for(1)->second(); + +$start->diffForHumans(); // 1 second ago +``` + Laravel uses the `Sleep` class internally whenever it is pausing execution. For example, the [`retry`](#method-retry) helper uses the `Sleep` class when sleeping, allowing for improved testability when using that helper.