Description
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.
public function __destruct()
{
if (! $this->shouldSleep) {
return;
}
if ($this->pending !== null) {
throw new RuntimeException('Unknown duration unit.');
}
// ...
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
use Illuminate\Support\Sleep;
Sleep::for($x);
In this case a \RuntimeException will be thrown with the same message "Unknown duration unit."