From ccaf2dc5b797da634e67188ce10b5708c37ff695 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 3 May 2024 15:24:59 +0200 Subject: [PATCH] Make the tests compatible with windows (and linux) --- .../unitary-tests/core/iTopConfigParserTest.php | 6 +++--- .../unattended-install/InstallationFileServiceTest.php | 4 ++-- .../setup/unattended-install/UnattendedInstallTest.php | 8 +++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php b/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php index 335016c396..60a39d4137 100644 --- a/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php +++ b/tests/php-unit-tests/unitary-tests/core/iTopConfigParserTest.php @@ -21,7 +21,7 @@ class iTopConfigParserTest extends ItopTestCase clearstatcache(); $this->sConfigPath = utils::GetConfigFilePath(); - $this->tmpSavePath = tempnam('/tmp/', 'config-itop'); + $this->tmpSavePath = tempnam(sys_get_temp_dir(), 'config-itop'); $this->conf_exists = is_file($this->sConfigPath); if ($this->conf_exists) @@ -156,8 +156,8 @@ class iTopConfigParserTest extends ItopTestCase */ public function testConfigWriteToFile() { - $tmpConfigFileBeforePath = tempnam( '/tmp/', 'config-itop'); - $tmpConfigFileAfterPath = tempnam( '/tmp/', 'config-itop'); + $tmpConfigFileBeforePath = tempnam( sys_get_temp_dir(), 'config-itop'); + $tmpConfigFileAfterPath = tempnam( sys_get_temp_dir(), 'config-itop'); //create new config file $sConfigFile = utils::GetConfig()->GetLoadedFile(); diff --git a/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php b/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php index b463cff36a..6b2f8196c6 100644 --- a/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/unattended-install/InstallationFileServiceTest.php @@ -287,8 +287,8 @@ class InstallationFileServiceTest extends ItopTestCase { private function GetMockListOfFoundModules() : array { $sJsonContent = file_get_contents(realpath(__DIR__ . '/resources/AnalyzeInstallation.json')); - $sJsonContent = str_replace('ROOTDIR_TOREPLACE', APPROOT, $sJsonContent); - return json_decode($sJsonContent, true); + $sJsonContent = str_replace('ROOTDIR_TOREPLACE', addslashes(APPROOT), $sJsonContent); + return json_decode($sJsonContent, true); } /** diff --git a/tests/php-unit-tests/unitary-tests/setup/unattended-install/UnattendedInstallTest.php b/tests/php-unit-tests/unitary-tests/setup/unattended-install/UnattendedInstallTest.php index cde7af01a4..77116c351f 100644 --- a/tests/php-unit-tests/unitary-tests/setup/unattended-install/UnattendedInstallTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/unattended-install/UnattendedInstallTest.php @@ -69,6 +69,12 @@ class UnattendedInstallTest extends ItopDataTestCase $sOutput = implode('\n', $aOutput); var_dump($sOutput); $this->assertStringContainsString("Missing mandatory argument `--param-file`", $sOutput); - $this->assertEquals(255, $iCode); + if (DIRECTORY_SEPARATOR === '\\') { + // Windows + $this->assertEquals(-1, $iCode); + } else { + // Linux + $this->assertEquals(255, $iCode); + } } }