N°5143 Fix FunctionExpression for DATE_FORMAT and formats %j, %k and %l

This commit is contained in:
Pierre Goiffon
2022-05-02 16:57:16 +02:00
parent 603934bac1
commit 84e35e27b8
2 changed files with 94 additions and 23 deletions

View File

@@ -455,7 +455,11 @@ class ExpressionEvaluateTest extends iTopDataTestCase
}
/**
* Systematically check all supported format specs, for a given date
* For a given date,
* for all different formats (1st array element returned by {@see static::TimeFormatsProvider}),
* compare value returned by :
* * DATE_FORMAT() SQL function,
* * FunctionExpression('DATE_FORMAT', ...) result
*
* @covers FunctionExpression::Evaluate()
* @dataProvider EveryTimeFormatProvider
@@ -481,7 +485,8 @@ class ExpressionEvaluateTest extends iTopDataTestCase
}
$sSelects = "SELECT ".implode(', ', $aSelects);
$aRes = CMDBSource::QueryToArray($sSelects);
$aRow = $aRes[0];
/** @var array $aMysqlDateFormatRsultsForAllFormats format as key, MySQL evaluated result as value */
$aMysqlDateFormatRsultsForAllFormats = $aRes[0];
foreach ($aFormats as $sFormatDesc => $aFormatSpec)
{
$sFormat = $aFormatSpec[0];
@@ -489,13 +494,8 @@ class ExpressionEvaluateTest extends iTopDataTestCase
if ($bProcessed)
{
$oExpression = new FunctionExpression('DATE_FORMAT', array(new ScalarExpression($sDate), new ScalarExpression("%$sFormat")));
$res = $oExpression->Evaluate(array());
if (is_numeric($res)) {
// N°3091 after PHPUnit upgrade from 6 to 8.5 some errors were thrown here
// example : assertEquals was returning false for expected=8 and actual=08
$res = (float) $res;
}
static::assertEquals($aRow[$sFormat], $res, "Format %$sFormat not matching MySQL for '$sDate'");
$itopExpressionResult = $oExpression->Evaluate(array());
static::assertSame($aMysqlDateFormatRsultsForAllFormats[$sFormat], $itopExpressionResult, "Format %$sFormat not matching MySQL for '$sDate'");
}
}
}