N°4261 - code review with @PirGoif

This commit is contained in:
bruno-ds
2021-09-21 16:37:58 +02:00
parent d9ccac3aea
commit c306c6e30d
3 changed files with 13 additions and 4 deletions

View File

@@ -1157,6 +1157,14 @@ class ExceptionLog extends LogAPI
$aContext['exception class'] = get_class($oException);
}
if (empty($aContext['file'])) {
$aContext['file'] = $oException->getFile();
}
if (empty($aContext['line'])) {
$aContext['line'] =$oException->getLine();
}
self::Log($sLevel, $oException->getMessage(), get_class($oException), $aContext);
}

View File

@@ -88,8 +88,6 @@ class ExceptionListener implements ContainerAwareInterface
// Log exception in iTop log
\ExceptionLog::LogException($oException, [
'uri' => $oEvent->getRequest()->getUri(),
'file' => $oException->getFile(),
'line' => $oException->getLine(),
]);
// Prepare data for template

View File

@@ -72,10 +72,13 @@ class ExceptionLogTest extends ItopDataTestCase
$aContext = ['contextKey1' => 'value'];
foreach ($aLevels as $i => $sLevel) {
$oException = new $aExceptions[$i]("Iteration number $i");
$sExpectedFile=__FILE__;
$oException = new $aExceptions[$i]("Iteration number $i"); $sExpectedLine = __LINE__; //Both should remain on the same line
$iExpectedWriteNumber = $aExpectedWriteNumber[$i];
$iExpectedDbWriteNumber = $aExpectedDbWriteNumber[$i];
$aExpectedFileContext = array_merge($aContext, ['exception class' => get_class($oException)]); //The context is preserved, and, if the key 'exception class' is not yet in the array, it is added
$aExpectedFileContext = array_merge($aContext, ['exception class' => get_class($oException), 'file' => $sExpectedFile, 'line' => $sExpectedLine]); //The context is preserved, and, if the key 'exception class' is not yet in the array, it is added
$mockFileLog->expects($this->exactly($iExpectedWriteNumber))
->method($sLevel)
->with($oException->GetMessage(), $sChannel, $aExpectedFileContext)