Skip to content

Commit 1e6b467

Browse files
authored
wip (#46963)
1 parent 1c783fe commit 1e6b467

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Illuminate/Support/Sleep.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public static function assertSequence($sequence)
359359
*/
360360
public static function assertNeverSlept()
361361
{
362-
return static::assertInsomniac();
362+
return static::assertSleptTimes(0);
363363
}
364364

365365
/**
@@ -369,6 +369,10 @@ public static function assertNeverSlept()
369369
*/
370370
public static function assertInsomniac()
371371
{
372+
if (static::$sequence === []) {
373+
PHPUnit::assertTrue(true);
374+
}
375+
372376
foreach (static::$sequence as $duration) {
373377
PHPUnit::assertSame(0, $duration->totalMicroseconds, vsprintf('Unexpected sleep duration of [%s] found.', [
374378
$duration->cascade()->forHumans([

tests/Support/SleepTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,38 @@ public function testItDoesntCaptureAssertionInstances()
305305
}
306306
}
307307

308+
public function testAssertNeverSlept()
309+
{
310+
Sleep::fake();
311+
312+
Sleep::assertNeverSlept();
313+
314+
Sleep::for(1)->seconds();
315+
316+
try {
317+
Sleep::assertNeverSlept();
318+
$this->fail();
319+
} catch (AssertionFailedError $e) {
320+
$this->assertSame("Expected [0] sleeps but found [1].\nFailed asserting that 1 is identical to 0.", $e->getMessage());
321+
}
322+
}
323+
324+
public function testAssertNeverAgainstZeroSecondSleep()
325+
{
326+
Sleep::fake();
327+
328+
Sleep::assertNeverSlept();
329+
330+
Sleep::for(0)->seconds();
331+
332+
try {
333+
Sleep::assertNeverSlept();
334+
$this->fail();
335+
} catch (AssertionFailedError $e) {
336+
$this->assertSame("Expected [0] sleeps but found [1].\nFailed asserting that 1 is identical to 0.", $e->getMessage());
337+
}
338+
}
339+
308340
public function testItCanAssertNoSleepingOccurred()
309341
{
310342
Sleep::fake();

0 commit comments

Comments
 (0)