diff --git a/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php b/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php index 1eaf4b6fd..c1bf7ba9e 100644 --- a/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php +++ b/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php @@ -18,6 +18,17 @@ namespace Combodo\iTop\Test\UnitTest\Integration; use Combodo\iTop\Test\UnitTest\ItopTestCase; + +/** + * Wrapper to load dictionnary files without altering the main dictionnary + * Eval will be called within the current namespace (this is done by adding a "namespace" statement) + */ +class Dict +{ + public static function Add($sLanguageCode, $sEnglishLanguageDesc, $sLocalizedLanguageDesc, $aEntries) + { + } +} /** * @group beforeSetup */ @@ -142,17 +153,40 @@ class DictionariesConsistencyTest extends ItopTestCase /** * @param string $sDictFile complete path for the file to check * @param bool $bIsSyntaxValid expected assert value - * - * @uses `php -l` - * @uses \assertEquals() */ private function CheckDictionarySyntax(string $sDictFile, $bIsSyntaxValid = true): void { - exec("php -l {$sDictFile}", $output, $return); - - $bDictFileSyntaxOk = ($return === 0); - - $sMessage = "File `{$sDictFile}` syntax didn't matched expectations\nparsing results=".var_export($output, true); - self::assertEquals($bIsSyntaxValid, $bDictFileSyntaxOk, $sMessage); + $sPHP = file_get_contents($sDictFile); + // Strip php tag to allow "eval" + $sPHP = substr(trim($sPHP), strlen(' No syntax error + if (!$bIsSyntaxValid) { + $this->fail("Failed to detect syntax error in dictionary `{$sDictFile}` (which is known as being INCORRECT)"); + } + } + catch (\Error $e) { + if ($bIsSyntaxValid) { + $iLine = $e->getLine() - $iLineShift; + $this->fail("Invalid dictionary: {$e->getMessage()} in {$sDictFile}:{$iLine}"); + } + } + catch (\Exception $e) { + if ($bIsSyntaxValid) { + $iLine = $e->getLine() - $iLineShift; + $sExceptionClass = get_class($e); + $this->fail("Exception thrown from dictionary: '$sExceptionClass: {$e->getMessage()}' in {$sDictFile}:{$iLine}"); + } + } + $this->assertTrue(true); } } diff --git a/tests/php-unit-tests/integration-tests/dictionaries-test/fr.dictionary.itop.core.OK.php b/tests/php-unit-tests/integration-tests/dictionaries-test/fr.dictionary.itop.core.OK.php index 3054d70fc..0658e7c86 100644 --- a/tests/php-unit-tests/integration-tests/dictionaries-test/fr.dictionary.itop.core.OK.php +++ b/tests/php-unit-tests/integration-tests/dictionaries-test/fr.dictionary.itop.core.OK.php @@ -1,10 +1,11 @@ + 'l\'échappement : bon exemple 1', + 'MyDictKey1' => 'l\'échappement : bon exemple 1'.ITOP_APPLICATION, 'MyDictKey2' => 'l\'échappement : bon exemple 2', 'MyDictKey3' => 'l\'échappement : bon exemple 3', ));