N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,27 +1,27 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Status;
use Combodo\iTop\Application\Status\Status;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
use Exception;
use MySQLException;
use function Combodo\iTop\Application\Status\StatusCheckConfigFile;
use function Combodo\iTop\Application\Status\StatusGetAppRoot;
use function Combodo\iTop\Application\Status\StatusStartup;
if (!defined('DEBUG_UNIT_TEST')) {
define('DEBUG_UNIT_TEST', true);
define('DEBUG_UNIT_TEST', true);
}
class StatusIncTest extends ItopTestCase {
/**
* @var string
*/
protected $sAppRoot = '';
class StatusIncTest extends ItopTestCase
{
/**
* @var string
*/
protected $sAppRoot = '';
protected function setUp(): void
{
@@ -29,59 +29,64 @@ class StatusIncTest extends ItopTestCase {
$this->RequireOnceItopFile('sources/Application/Status/Status.php');
}
public function testStatusGetAppRootWrongPath() {
public function testStatusGetAppRootWrongPath()
{
$this->expectException(Exception::class);
$sAppRootFilenamewrong = 'approot.inc.php_wrong';
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusGetAppRoot", $oStatus, [$sAppRootFilenamewrong]);
}
}
/**
*
*/
public function testStatusGetAppRootGood() {
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusGetAppRoot", $oStatus, []);
/**
*
*/
public function testStatusGetAppRootGood()
{
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusGetAppRoot", $oStatus, []);
$this->assertNotEmpty(APPROOT);
}
$this->assertNotEmpty(APPROOT);
}
public function testStatusCheckConfigFileWrongPath() {
public function testStatusCheckConfigFileWrongPath()
{
$this->expectException(Exception::class);
$sConfigFilenamewrong = 'config-itop.php_wrong';
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusCheckConfigFile", $oStatus, [$sConfigFilenamewrong]);
}
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusCheckConfigFile", $oStatus, [$sConfigFilenamewrong]);
}
public function testStatusCheckConfigFileGood() {
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusCheckConfigFile", $oStatus, []);
public function testStatusCheckConfigFileGood()
{
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusCheckConfigFile", $oStatus, []);
$this->assertTrue(true);
}
$this->assertTrue(true);
}
/**
* @runInSeparateProcess Required because Status constructor invokes MetaModel::Startup... which does nothing when already loaded
*/
/**
* @runInSeparateProcess Required because Status constructor invokes MetaModel::Startup... which does nothing when already loaded
*/
public function testStatusStartupWrongDbPwd()
{
$this->RequireOnceItopFile('core/cmdbobject.class.inc.php');
$this->RequireOnceItopFile('application/utils.inc.php');
$this->RequireOnceItopFile('core/contexttag.class.inc.php');
{
$this->RequireOnceItopFile('core/cmdbobject.class.inc.php');
$this->RequireOnceItopFile('application/utils.inc.php');
$this->RequireOnceItopFile('core/contexttag.class.inc.php');
$oConfigWrong = new Config(ITOP_DEFAULT_CONFIG_FILE);
$oConfigWrong->Set('db_pwd', $oConfigWrong->Get('db_pwd').'_unittest');
$this->expectException(MySQLException::class);
new Status($oConfigWrong);
}
$oConfigWrong = new Config(ITOP_DEFAULT_CONFIG_FILE);
$oConfigWrong->Set('db_pwd', $oConfigWrong->Get('db_pwd').'_unittest');
$this->expectException(MySQLException::class);
new Status($oConfigWrong);
}
public function testStatusStartupGood() {
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusStartup", $oStatus, []);
public function testStatusStartupGood()
{
$oStatus = new Status();
$this->InvokeNonPublicMethod(Status::class, "StatusStartup", $oStatus, []);
$this->assertTrue(true);
}
$this->assertTrue(true);
}
}

View File

@@ -28,7 +28,7 @@ class StatusTest extends ItopTestCase
$sPath = APPROOT.'/webservices/status.php';
$sPHP = $this->GetPHPCommand();
echo "About to execute: $sPHP $sPath\n";
echo "About to execute: $sPHP $sPath\n";
exec("$sPHP $sPath", $aOutput, $iRet);
$this->assertEquals(0, $iRet, "Problem executing status page: $sPath, $iRet, aOutput:\n".var_export($aOutput, true));

View File

@@ -5,21 +5,18 @@
require_once __DIR__.'/../../../../../../sources/application/status/Status.php';
// Do check Status
try
{
\Combodo\iTop\Application\Status\StatusStartup();
$aResult = array('status' => STATUS_RUNNING, 'code' => \RestResult::OK, 'message' => '');
}
catch (\Exception $e)
{
$iCode = (defined('\RestResult::INTERNAL_ERROR')) ? \RestResult::INTERNAL_ERROR : 100;
$aResult = array('status' => STATUS_ERROR, 'code' => $iCode, 'message' => $e->getMessage());
http_response_code(500);
try {
\Combodo\iTop\Application\Status\StatusStartup();
$aResult = ['status' => STATUS_RUNNING, 'code' => \RestResult::OK, 'message' => ''];
} catch (\Exception $e) {
$iCode = (defined('\RestResult::INTERNAL_ERROR')) ? \RestResult::INTERNAL_ERROR : 100;
$aResult = ['status' => STATUS_ERROR, 'code' => $iCode, 'message' => $e->getMessage()];
http_response_code(500);
}
//Set headers, based on webservices/rest.php
$sContentType = 'application/json';
header('Content-type: ' . $sContentType);
header('Content-type: '.$sContentType);
header('Access-Control-Allow-Origin: *');
//Output result