mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°8129 - Dont crash if date/time default value has a bad format
This commit is contained in:
@@ -1492,6 +1492,15 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
$this->assertEquals(1, $oSet->Count(), $sMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.2.1
|
||||
*/
|
||||
protected function AssertLastErrorLogEntryContains(string $sNeedle, string $sMessage = ''): void
|
||||
{
|
||||
$aLastLines = self::ReadTail(APPROOT.'/log/error.log');
|
||||
$this->assertStringContainsString($sNeedle, $aLastLines[0], $sMessage);
|
||||
}
|
||||
|
||||
static protected function StartStopwatchInThePast(DBObject $oObject, string $sStopwatchAttCode, int $iDelayInSecond)
|
||||
{
|
||||
$iStartDate = time() - $iDelayInSecond;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace Combodo\iTop\Test\UnitTest;
|
||||
|
||||
use CMDBSource;
|
||||
use DateTime;
|
||||
use DeprecatedCallsLog;
|
||||
use MySQLTransactionNotClosedException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -550,6 +551,31 @@ abstract class ItopTestCase extends TestCase
|
||||
$this->AssertArraysHaveSameItems($aExpected, $aFiles, $sMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.2.1
|
||||
*/
|
||||
static protected function AssertDateEqualsNow($sActualDate, $sMessage = ''): void
|
||||
{
|
||||
$oActualDate = \DateTime::createFromFormat(\AttributeDate::GetInternalFormat(), $sActualDate);
|
||||
$oNow = new DateTime();
|
||||
|
||||
$iTimeInterval = $oNow->diff($oActualDate)->s;
|
||||
|
||||
self::assertLessThan(2, $iTimeInterval, $sMessage);
|
||||
}
|
||||
/**
|
||||
* @since 3.2.1
|
||||
*/
|
||||
static protected function AssertDateTimeEqualsNow($sActualDate, $sMessage = ''): void
|
||||
{
|
||||
$oActualDateTime = \DateTime::createFromFormat(\AttributeDateTime::GetInternalFormat(), $sActualDate);
|
||||
$oNow = new DateTime();
|
||||
|
||||
$iTimeInterval = $oNow->diff($oActualDateTime)->s;
|
||||
|
||||
self::assertLessThan(2, $iTimeInterval, $sMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Control which Kernel will be loaded when invoking the bootKernel method
|
||||
*
|
||||
@@ -572,4 +598,37 @@ abstract class ItopTestCase extends TestCase
|
||||
}
|
||||
return parent::bootKernel($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Ain Tohvri <https://mstdn.social/@tekkie>
|
||||
*
|
||||
* @since 3.2.1
|
||||
*/
|
||||
static protected function ReadTail($sFilename, $iLines = 1)
|
||||
{
|
||||
$handle = fopen($sFilename, "r");
|
||||
$iLineCounter = $iLines;
|
||||
$iPos = -2;
|
||||
$bBeginning = false;
|
||||
$aLines = array();
|
||||
while ($iLineCounter > 0) {
|
||||
$sChar = " ";
|
||||
while ($sChar != "\n") {
|
||||
if(fseek($handle, $iPos, SEEK_END) == -1) {
|
||||
$bBeginning = true;
|
||||
break;
|
||||
}
|
||||
$sChar = fgetc($handle);
|
||||
$iPos --;
|
||||
}
|
||||
$iLineCounter --;
|
||||
if ($bBeginning) {
|
||||
rewind($handle);
|
||||
}
|
||||
$aLines[$iLines - $iLineCounter - 1] = fgets($handle);
|
||||
if ($bBeginning) break;
|
||||
}
|
||||
fclose ($handle);
|
||||
return array_reverse($aLines);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user