New tests to check syntax of all dict files

We had some issues last week with invalid PHP syntax in dict files. The CI detects some of these, but having a larger check with a clearer message that is run immediately at commit will ease fixing such issues !
This commit is contained in:
Pierre Goiffon
2021-03-31 16:00:02 +02:00
parent 131ecd5e3b
commit c843e13c58
3 changed files with 2285 additions and 2 deletions

View File

@@ -100,10 +100,52 @@ class DictionariesConsistencyTest extends ItopTestCase
glob(APPROOT.'dictionaries/*.dict*.php') // framework
);
$aTestCases = array();
foreach ($aDictFiles as $sDictFile)
{
foreach ($aDictFiles as $sDictFile) {
$aTestCases[$sDictFile] = array('sDictFile' => $sDictFile);
}
return $aTestCases;
}
/**
* @dataProvider DictionaryFileProvider
*
* @param string $sDictFile
*
* @uses CheckDictionarySyntax
*/
public function testStandardDictionariesPhpSyntax(string $sDictFile): void
{
$this->CheckDictionarySyntax($sDictFile);
}
/**
* Checks that {@see CheckDictionarySyntax} works as expected by passing 2 test dictionaries
*
* @uses CheckDictionarySyntax
*/
public function testPlaygroundDictionariesPhpSyntax(): void
{
$this->CheckDictionarySyntax(__DIR__.'/dictionaries-test/fr.dictionary.itop.core.KO.php', false);
/** @noinspection PhpRedundantOptionalArgumentInspection */
$this->CheckDictionarySyntax(__DIR__.'/dictionaries-test/fr.dictionary.itop.core.OK.php', true);
}
/**
* @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);
var_dump($sDictFile, $return, $output);
$bDictFileSyntaxOk = ($return === 0);
$sMessage = "File `{$sDictFile}` syntax didn't matched expectations\nparsing results=".var_export($output, true);
$this->assertEquals($bIsSyntaxValid, $bDictFileSyntaxOk, $sMessage);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff