mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-01 07:04:16 +01:00
Merge remote-tracking branch 'origin/support/3.2' into develop
# Conflicts: # tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php
This commit is contained in:
@@ -440,6 +440,14 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
$this->RemoveObjects($sTagClass, "SELECT $sTagClass WHERE code = '$sTagCode'");
|
||||
}
|
||||
|
||||
public function RemoveAllObjects($sClassName)
|
||||
{
|
||||
$oSet = new \DBObjectSet(new \DBObjectSearch($sClassName));
|
||||
while ($oObject = $oSet->Fetch()) {
|
||||
$oObject->DBDelete();
|
||||
}
|
||||
}
|
||||
|
||||
private function RemoveObjects($sClass, $sOQL)
|
||||
{
|
||||
$oFilter = DBSearch::FromOQL($sOQL);
|
||||
@@ -930,11 +938,12 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
*
|
||||
* @param $iExpectedCount Number of MySQL queries that should be executed
|
||||
* @param callable $oFunction Operations to perform
|
||||
* @param string $sMessage Message to display in case of failure
|
||||
*
|
||||
* @throws \MySQLException
|
||||
* @throws \MySQLQueryHasNoResultException
|
||||
*/
|
||||
protected function assertDBQueryCount($iExpectedCount, callable $oFunction)
|
||||
protected function assertDBQueryCount($iExpectedCount, callable $oFunction, $sMessage = '')
|
||||
{
|
||||
$iInitialCount = (int) CMDBSource::QueryToScalar("SHOW SESSION STATUS LIKE 'Queries'", 1);
|
||||
$oFunction();
|
||||
@@ -942,7 +951,13 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
$iCount = $iFinalCount - 1 - $iInitialCount;
|
||||
if ($iCount != $iExpectedCount)
|
||||
{
|
||||
$this->fail("Expected $iExpectedCount queries. $iCount have been executed.");
|
||||
if ($sMessage === '') {
|
||||
$sMessage = "Expected $iExpectedCount queries. $iCount have been executed.";
|
||||
}
|
||||
else {
|
||||
$sMessage .= " - Expected $iExpectedCount queries. $iCount have been executed.";
|
||||
}
|
||||
$this->fail($sMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -965,6 +980,18 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
$this->assertEquals($iExpectedCount, $iCount, "Found $iCount changes for object $sClass::$iId");
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected static function assertIsDBObject(string $sExpectedClass, ?int $iExpectedKey, $oObject, ?string $sMessage = '')
|
||||
{
|
||||
self::assertNotNull($oObject, $sMessage);
|
||||
self::assertInstanceOf($sExpectedClass, $oObject, $sMessage);
|
||||
if ($iExpectedKey !== null) {
|
||||
self::assertEquals($iExpectedKey, $oObject->GetKey(), $sMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a set of XML files describing a consistent set of iTop objects
|
||||
* @param string[] $aFiles
|
||||
@@ -1464,4 +1491,28 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
$this->assertEquals(1, $oSet->Count(), $sMessage);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user