From a4b0b6e855d482b8dfd483643fd567718d8b8b5a Mon Sep 17 00:00:00 2001 From: odain Date: Fri, 19 Dec 2025 09:54:43 +0100 Subject: [PATCH 1/5] ci: rename CallItopUrl by CallUrl + cleanup --- .../src/BaseTestCase/ItopTestCase.php | 7 +-- .../unitary-tests/application/LoginTest.php | 62 ------------------- .../application/query/QueryTest.php | 3 +- 3 files changed, 5 insertions(+), 67 deletions(-) delete mode 100644 tests/php-unit-tests/unitary-tests/application/LoginTest.php diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php index 6e30f5ed4..ef1c6ac05 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php @@ -8,14 +8,12 @@ namespace Combodo\iTop\Test\UnitTest; use CMDBSource; -use DateTime; use DeprecatedCallsLog; use MySQLTransactionNotClosedException; use ReflectionMethod; use SetupUtils; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; - use const DEBUG_BACKTRACE_IGNORE_ARGS; /** @@ -649,7 +647,7 @@ abstract class ItopTestCase extends KernelTestCase * @param $bXDebugEnabled * @return string */ - protected function CallItopUrl($sUrl, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string + protected function CallUrl($sUrl, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string { $ch = curl_init(); if ($bXDebugEnabled) { @@ -687,6 +685,7 @@ abstract class ItopTestCase extends KernelTestCase protected function CallItopUri(string $sUri, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string { $sUrl = \MetaModel::GetConfig()->Get('app_root_url')."/$sUri"; - return $this->CallItopUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled); + + return $this->CallUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled); } } diff --git a/tests/php-unit-tests/unitary-tests/application/LoginTest.php b/tests/php-unit-tests/unitary-tests/application/LoginTest.php deleted file mode 100644 index cea8785c7..000000000 --- a/tests/php-unit-tests/unitary-tests/application/LoginTest.php +++ /dev/null @@ -1,62 +0,0 @@ -sConfigPath = MetaModel::GetConfig()->GetLoadedFile(); - $this->sConfigTmpBackupFile = tempnam(sys_get_temp_dir(), "config_"); - file_put_contents($this->sConfigTmpBackupFile, file_get_contents($this->sConfigPath)); - - $oConfig = new \Config($this->sConfigPath); - $this->sLoginMode = "unimplemented_loginmode"; - $oConfig->AddAllowedLoginTypes($this->sLoginMode); - - @chmod($this->sConfigPath, 0770); - $oConfig->WriteToFile(); - @chmod($this->sConfigPath, 0444); - } - - protected function tearDown(): void - { - if (! is_null($this->sConfigTmpBackupFile) && is_file($this->sConfigTmpBackupFile)) { - //put config back - @chmod($this->sConfigPath, 0770); - file_put_contents($this->sConfigPath, file_get_contents($this->sConfigTmpBackupFile)); - @chmod($this->sConfigPath, 0444); - @unlink($this->sConfigTmpBackupFile); - } - parent::tearDown(); - } - - protected function CallItopUrlByCurl($sUri, ?array $aPostFields = []) - { - $ch = curl_init(); - - $sUrl = MetaModel::GetConfig()->Get('app_root_url')."/$sUri"; - curl_setopt($ch, CURLOPT_URL, $sUrl); - if (0 !== sizeof($aPostFields)) { - curl_setopt($ch, CURLOPT_POST, 1);// set post data to true - curl_setopt($ch, CURLOPT_POSTFIELDS, $aPostFields); - } - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $sOutput = curl_exec($ch); - curl_close($ch); - - return $sOutput; - } -} diff --git a/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php b/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php index 63521d74d..efbe9f57d 100644 --- a/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php +++ b/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php @@ -147,7 +147,8 @@ class QueryTest extends ItopDataTestCase CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => self::USER.':'.self::PASSWORD, ]; - return $this->CallItopUrl($url, [], $aCurlOptions); + + return $this->CallUrl($url, [], $aCurlOptions); } /** @inheritDoc */ From 1fe401c1027134d48d077d9d9bb08a73220a28e4 Mon Sep 17 00:00:00 2001 From: odain Date: Fri, 19 Dec 2025 09:54:43 +0100 Subject: [PATCH 2/5] ci: rename CallItopUrl by CallUrl + cleanup --- .../src/BaseTestCase/ItopTestCase.php | 6 +- .../unitary-tests/application/LoginTest.php | 62 ------------------- .../application/query/QueryTest.php | 3 +- 3 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 tests/php-unit-tests/unitary-tests/application/LoginTest.php diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php index fda6aa523..e2f409a86 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php @@ -14,7 +14,6 @@ use ReflectionMethod; use SetupUtils; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; - use const DEBUG_BACKTRACE_IGNORE_ARGS; /** @@ -649,7 +648,7 @@ abstract class ItopTestCase extends KernelTestCase * @param $bXDebugEnabled * @return string */ - protected function CallItopUrl($sUrl, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string + protected function CallUrl($sUrl, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string { $ch = curl_init(); if ($bXDebugEnabled) { @@ -687,6 +686,7 @@ abstract class ItopTestCase extends KernelTestCase protected function CallItopUri(string $sUri, ?array $aPostFields = [], ?array $aCurlOptions = [], $bXDebugEnabled = false): string { $sUrl = \MetaModel::GetConfig()->Get('app_root_url')."/$sUri"; - return $this->CallItopUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled); + + return $this->CallUrl($sUrl, $aPostFields, $aCurlOptions, $bXDebugEnabled); } } diff --git a/tests/php-unit-tests/unitary-tests/application/LoginTest.php b/tests/php-unit-tests/unitary-tests/application/LoginTest.php deleted file mode 100644 index cea8785c7..000000000 --- a/tests/php-unit-tests/unitary-tests/application/LoginTest.php +++ /dev/null @@ -1,62 +0,0 @@ -sConfigPath = MetaModel::GetConfig()->GetLoadedFile(); - $this->sConfigTmpBackupFile = tempnam(sys_get_temp_dir(), "config_"); - file_put_contents($this->sConfigTmpBackupFile, file_get_contents($this->sConfigPath)); - - $oConfig = new \Config($this->sConfigPath); - $this->sLoginMode = "unimplemented_loginmode"; - $oConfig->AddAllowedLoginTypes($this->sLoginMode); - - @chmod($this->sConfigPath, 0770); - $oConfig->WriteToFile(); - @chmod($this->sConfigPath, 0444); - } - - protected function tearDown(): void - { - if (! is_null($this->sConfigTmpBackupFile) && is_file($this->sConfigTmpBackupFile)) { - //put config back - @chmod($this->sConfigPath, 0770); - file_put_contents($this->sConfigPath, file_get_contents($this->sConfigTmpBackupFile)); - @chmod($this->sConfigPath, 0444); - @unlink($this->sConfigTmpBackupFile); - } - parent::tearDown(); - } - - protected function CallItopUrlByCurl($sUri, ?array $aPostFields = []) - { - $ch = curl_init(); - - $sUrl = MetaModel::GetConfig()->Get('app_root_url')."/$sUri"; - curl_setopt($ch, CURLOPT_URL, $sUrl); - if (0 !== sizeof($aPostFields)) { - curl_setopt($ch, CURLOPT_POST, 1);// set post data to true - curl_setopt($ch, CURLOPT_POSTFIELDS, $aPostFields); - } - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $sOutput = curl_exec($ch); - curl_close($ch); - - return $sOutput; - } -} diff --git a/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php b/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php index b8cc38bca..c6fbffec1 100644 --- a/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php +++ b/tests/php-unit-tests/unitary-tests/application/query/QueryTest.php @@ -176,7 +176,8 @@ class QueryTest extends ItopDataTestCase CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => self::USER.':'.self::PASSWORD, ]; - return $this->CallItopUrl($url, [], $aCurlOptions); + + return $this->CallUrl($url, [], $aCurlOptions); } /** @inheritDoc */ From d552727c55c35abb975e8c1cdf1c1c2d2cda501c Mon Sep 17 00:00:00 2001 From: odain Date: Fri, 19 Dec 2025 10:38:48 +0100 Subject: [PATCH 3/5] ci: fix code style --- tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php index ef1c6ac05..8ea739ca7 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php @@ -14,6 +14,7 @@ use ReflectionMethod; use SetupUtils; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; + use const DEBUG_BACKTRACE_IGNORE_ARGS; /** From 3df4ddc6964eb1049593fec934b3a98108b0dc7d Mon Sep 17 00:00:00 2001 From: odain Date: Fri, 19 Dec 2025 10:39:15 +0100 Subject: [PATCH 4/5] ci: fix code style --- tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php index e2f409a86..b00b6368a 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php @@ -14,6 +14,7 @@ use ReflectionMethod; use SetupUtils; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; + use const DEBUG_BACKTRACE_IGNORE_ARGS; /** From 09afcb229ce0ae096e49e48d2ddda1820f9077ba Mon Sep 17 00:00:00 2001 From: odain Date: Fri, 19 Dec 2025 11:11:03 +0100 Subject: [PATCH 5/5] ci: fix callUrl with posted params --- tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php index b00b6368a..0c4742379 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php @@ -658,20 +658,14 @@ abstract class ItopTestCase extends KernelTestCase curl_setopt($ch, CURLOPT_URL, $sUrl); curl_setopt($ch, CURLOPT_POST, 1);// set post data to true - if (!is_array($aPostFields)) { - var_dump($aPostFields); - } - curl_setopt($ch, CURLOPT_POSTFIELDS, $aPostFields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Force disable of certificate check as most of dev / test env have a self-signed certificate curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - - var_dump($aCurlOptions); curl_setopt_array($ch, $aCurlOptions); + curl_setopt($ch, CURLOPT_POSTFIELDS, $aPostFields); $sOutput = curl_exec($ch); - //\IssueLog::Info("$sUrl error code:", null, ['error' => curl_error($ch)]); $info = curl_getinfo($ch); $this->aLastCurlGetInfo = $info;