Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald authored May 5, 2023
1 parent 1c783fe commit 1e6b467
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Support/Sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public static function assertSequence($sequence)
*/
public static function assertNeverSlept()
{
return static::assertInsomniac();
return static::assertSleptTimes(0);
}

/**
Expand All @@ -369,6 +369,10 @@ public static function assertNeverSlept()
*/
public static function assertInsomniac()
{
if (static::$sequence === []) {
PHPUnit::assertTrue(true);
}

foreach (static::$sequence as $duration) {
PHPUnit::assertSame(0, $duration->totalMicroseconds, vsprintf('Unexpected sleep duration of [%s] found.', [
$duration->cascade()->forHumans([
Expand Down
32 changes: 32 additions & 0 deletions tests/Support/SleepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@ public function testItDoesntCaptureAssertionInstances()
}
}

public function testAssertNeverSlept()
{
Sleep::fake();

Sleep::assertNeverSlept();

Sleep::for(1)->seconds();

try {
Sleep::assertNeverSlept();
$this->fail();
} catch (AssertionFailedError $e) {
$this->assertSame("Expected [0] sleeps but found [1].\nFailed asserting that 1 is identical to 0.", $e->getMessage());
}
}

public function testAssertNeverAgainstZeroSecondSleep()
{
Sleep::fake();

Sleep::assertNeverSlept();

Sleep::for(0)->seconds();

try {
Sleep::assertNeverSlept();
$this->fail();
} catch (AssertionFailedError $e) {
$this->assertSame("Expected [0] sleeps but found [1].\nFailed asserting that 1 is identical to 0.", $e->getMessage());
}
}

public function testItCanAssertNoSleepingOccurred()
{
Sleep::fake();
Expand Down

0 comments on commit 1e6b467

Please sign in to comment.