Skip to content

Commit fe5e22c

Browse files
authored
Prevent unintended sleep on early failure of assertSequence (#56583)
1 parent b10312f commit fe5e22c

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

src/Illuminate/Support/Sleep.php

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -428,29 +428,37 @@ public static function assertSleptTimes($expected)
428428
*/
429429
public static function assertSequence($sequence)
430430
{
431-
static::assertSleptTimes(count($sequence));
432-
433-
(new Collection($sequence))
434-
->zip(static::$sequence)
435-
->eachSpread(function (?Sleep $expected, CarbonInterval $actual) {
436-
if ($expected === null) {
437-
return;
431+
try {
432+
static::assertSleptTimes(count($sequence));
433+
434+
(new Collection($sequence))
435+
->zip(static::$sequence)
436+
->eachSpread(function (?Sleep $expected, CarbonInterval $actual) {
437+
if ($expected === null) {
438+
return;
439+
}
440+
441+
PHPUnit::assertTrue(
442+
$expected->shouldNotSleep()->duration->equalTo($actual),
443+
vsprintf('Expected sleep duration of [%s] but actually slept for [%s].', [
444+
$expected->duration->cascade()->forHumans([
445+
'options' => 0,
446+
'minimumUnit' => 'microsecond',
447+
]),
448+
$actual->cascade()->forHumans([
449+
'options' => 0,
450+
'minimumUnit' => 'microsecond',
451+
]),
452+
])
453+
);
454+
});
455+
} finally {
456+
foreach ($sequence as $expected) {
457+
if ($expected instanceof self) {
458+
$expected->shouldNotSleep();
438459
}
439-
440-
PHPUnit::assertTrue(
441-
$expected->shouldNotSleep()->duration->equalTo($actual),
442-
vsprintf('Expected sleep duration of [%s] but actually slept for [%s].', [
443-
$expected->duration->cascade()->forHumans([
444-
'options' => 0,
445-
'minimumUnit' => 'microsecond',
446-
]),
447-
$actual->cascade()->forHumans([
448-
'options' => 0,
449-
'minimumUnit' => 'microsecond',
450-
]),
451-
])
452-
);
453-
});
460+
}
461+
}
454462
}
455463

456464
/**

0 commit comments

Comments
 (0)