-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unknown duration unit when using Sleep::for() with integers/floats #49887
Comments
If using method |
Heya, thanks for reporting. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up. laravel new bug-report --github="--public" Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
I am unable to reproduce this exception. I created a fresh laravel application and added the following command to the Artisan::command('sleep', function () {
\Illuminate\Support\Sleep::for(CarbonInterval::seconds(1));
\Illuminate\Support\Sleep::for(1.5)->seconds();
\Illuminate\Support\Sleep::for(1.5)->milliseconds();
}); The artisan command runs as expected and no exception is not thrown. If the exception being thrown has the message e.g. See the docs for usage examples: https://laravel.com/docs/10.x/helpers#sleep |
You are right. I did not add the scalar, I thought if none is set a default one will be assumed (seconds or u-seconds). Thank you. |
Laravel Version
10.40.0
PHP Version
8.2
Database Driver & Version
No DB, macOS 14.3 (23D56) with Herd 1.0.0
Description
As per Sleep class in Laravel int and floats are accepted, but actually sending integers or floats will trigger an error.
Sleep::for(); accepts \DateInterval|int|float $duration // according to phpdoc
which calls the Sleep constructor, which also accepts int|float|\DateInterval $duration // according to phpdoc
which calls Sleep::duration(), which also accepts \DateInterval|int|float $duration // according to phpdoc
All functions will execute successfully however when Sleep::__destruct() is called the exception is thrown due to $this->pending not being a null value.
Is this an expected behaviour keeping possible concurrency in mind?
Am I missing something?
Steps To Reproduce
Write a new unit test, and call Sleep::for($x).
The variable $x must be integer or a float.
The following exception
• Tests\Feature\SleepTest > pretendSleep
PHPUnit\Framework\ExceptionWrapper
Unknown duration unit.
The same can be achieved by running the snippet below
In this case a \RuntimeException will be thrown with the same message "Unknown duration unit."
The text was updated successfully, but these errors were encountered: