saveClockBeforeTest example


trait ClockSensitiveTrait
{
    public static function mockTime(string|\DateTimeImmutable|bool $when = true): ClockInterface
    {
        Clock::set(match (true) {
            false === $when => self::saveClockBeforeTest(false),
            true === $when => new MockClock(),
            $when instanceof \DateTimeImmutable => new MockClock($when),
            default => new MockClock(now()->modify($when)),
        });

        return Clock::get();
    }

    /** * @before * * @internal */
Home | Imprint | This part of the site doesn't use cookies.