Add helpers for stopwatches manipulation

This commit is contained in:
v-dumas
2025-01-03 17:04:41 +01:00
parent 71b3a415a6
commit a91de9fb36

View File

@@ -1433,4 +1433,28 @@ abstract class ItopDataTestCase extends ItopTestCase
self::markTestSkipped("Test skipped: module '$sModule' is not present");
}
}
static protected function StartStopwatchInThePast(DBObject $oObject, string $sStopwatchAttCode, int $iDelayInSecond)
{
$iStartDate = time() - $iDelayInSecond;
/** @var \ormStopWatch $oStopwatch */
$oStopwatch = $oObject->Get($sStopwatchAttCode);
$oAttDef = MetaModel::GetAttributeDef(get_class($oObject), $sStopwatchAttCode);
$oStopwatch->Start($oObject, $oAttDef, $iStartDate);
$oStopwatch->ComputeDeadlines($oObject, $oAttDef);
$oObject->Set($sStopwatchAttCode, $oStopwatch);
}
static protected function StopStopwatchInTheFuture(DBObject $oObject, string $sStopwatchAttCode, int $iDelayInSecond)
{
$iEndDate = time() + $iDelayInSecond;
/** @var \ormStopWatch $oStopwatch */
$oStopwatch = $oObject->Get($sStopwatchAttCode);
$oAttDef = MetaModel::GetAttributeDef(get_class($oObject), $sStopwatchAttCode);
$oStopwatch->Stop($oObject, $oAttDef, $iEndDate);
$oStopwatch->ComputeDeadlines($oObject, $oAttDef);
$oObject->Set($sStopwatchAttCode, $oStopwatch);
}
}