CloudCastle Clock

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano

Esempi

Retry con sleep virtuale

$clock = MockClock::from('2026-01-01 00:00:00', 'UTC');
$attempts = 0;

while ($attempts < 5) {
    if ($api->try()) {
        break;
    }

    ++$attempts;
    $clock->sleep(2 ** $attempts);   // istantaneo nel test
}

Chiave di cache al minuto

$byMinute = TruncatingClock::toMinute(SystemClock::utc());
$key = 'rates:' . $byMinute->timestamp();

Serie di eventi in un test

$clock = StepClock::from('2026-01-01 00:00:00', TimeSpan::ofMinutes(5), 'UTC');

foreach ($batch as $message) {
    $log->record($message, $clock->now());   // 00:00, 00:05, 00:10...
}

Misurazione delle fasi

$watch = Stopwatch::start();
$loader->import();
$watch->lap('importazione');
$indexer->rebuild();
$watch->lap('indicizzazione');
$metrics->timing('job.total', $watch->stop());

Sostituzione del tempo a scope

$report = ClockHolder::within(
    FrozenClock::from('2026-03-31 23:59:59', 'UTC'),
    fn () => $builder->quarterReport(),
);

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano