From 898db959b7f4e788b791c93d306b41e185cbf13b Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 5 May 2023 11:22:36 +1000 Subject: [PATCH] wip --- src/Illuminate/Support/Sleep.php | 6 +++++- tests/Support/SleepTest.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Sleep.php b/src/Illuminate/Support/Sleep.php index d4ee90f261e1..041535b9b42f 100644 --- a/src/Illuminate/Support/Sleep.php +++ b/src/Illuminate/Support/Sleep.php @@ -359,7 +359,7 @@ public static function assertSequence($sequence) */ public static function assertNeverSlept() { - return static::assertInsomniac(); + return static::assertSleptTimes(0); } /** @@ -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([ diff --git a/tests/Support/SleepTest.php b/tests/Support/SleepTest.php index 38b456893ec9..13c7ed4d9d3b 100644 --- a/tests/Support/SleepTest.php +++ b/tests/Support/SleepTest.php @@ -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();