mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 10:08:45 +02:00
✅ 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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
1128
test/integration/dictionaries-test/fr.dictionary.itop.core.KO.php
Normal file
1128
test/integration/dictionaries-test/fr.dictionary.itop.core.KO.php
Normal file
File diff suppressed because it is too large
Load Diff
1113
test/integration/dictionaries-test/fr.dictionary.itop.core.OK.php
Normal file
1113
test/integration/dictionaries-test/fr.dictionary.itop.core.OK.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user