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

@@ -30,15 +30,15 @@ class DataModelDependantCacheTest extends ItopTestCase
}
public function testShouldStoreAndFetchVariousDataTypes(): void
{
$this->oCacheService->Store('pool-A', 'key-array', ['value1', 'value2']);
$this->oCacheService->Store('pool-A', 'key-string', 'foo');
$this->oCacheService->Store('pool-A', 'key-int', 1971);
{
$this->oCacheService->Store('pool-A', 'key-array', ['value1', 'value2']);
$this->oCacheService->Store('pool-A', 'key-string', 'foo');
$this->oCacheService->Store('pool-A', 'key-int', 1971);
$this->assertEquals(['value1', 'value2'], $this->oCacheService->Fetch('pool-A', 'key-array'));
$this->assertEquals('foo', $this->oCacheService->Fetch('pool-A', 'key-string'));
$this->assertEquals(1971, $this->oCacheService->Fetch('pool-A', 'key-int'));
}
$this->assertEquals('foo', $this->oCacheService->Fetch('pool-A', 'key-string'));
$this->assertEquals(1971, $this->oCacheService->Fetch('pool-A', 'key-int'));
}
public function testShouldNotAllowToStoreNull(): void
{

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -23,9 +24,9 @@ use TypeError;
*/
class EventTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;
const CREATE_TEST_ORG = false;
const DEBUG_UNIT_TEST = true;
public const USE_TRANSACTION = false;
public const CREATE_TEST_ORG = false;
public const DEBUG_UNIT_TEST = true;
private static int $iEventCalls;
@@ -99,18 +100,18 @@ class EventTest extends ItopDataTestCase
{
$oReceiver = new TestEventReceiver();
return array(
'method' => array(array($oReceiver, 'OnEvent1')),
'static' => array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent1'),
'static2' => array(array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1')),
);
return [
'method' => [[$oReceiver, 'OnEvent1']],
'static' => ['Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent1'],
'static2' => [['Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1']],
];
}
public function testBrokenCallback()
{
EventService::RegisterEvent(new EventDescription('event_a', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$this->EventService_RegisterListener('event_a', array($oReceiver, 'BrokenCallback'));
$this->EventService_RegisterListener('event_a', [$oReceiver, 'BrokenCallback']);
$this->expectException(TypeError::class);
EventService::FireEvent(new EventData('event_a'));
@@ -120,7 +121,7 @@ class EventTest extends ItopDataTestCase
{
EventService::RegisterEvent(new EventDescription('event_a', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$this->EventService_RegisterListener('event_a', array($oReceiver, 'OnEvent1'));
$this->EventService_RegisterListener('event_a', [$oReceiver, 'OnEvent1']);
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event_a'));
@@ -140,14 +141,14 @@ class EventTest extends ItopDataTestCase
EventService::RegisterEvent(new EventDescription('event_a', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event_b', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$this->EventService_RegisterListener('event_a', array($oReceiver, 'OnEvent1'));
$this->EventService_RegisterListener('event_a', array($oReceiver, 'OnEvent2'));
$this->EventService_RegisterListener('event_a', array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1'));
$this->EventService_RegisterListener('event_a', [$oReceiver, 'OnEvent1']);
$this->EventService_RegisterListener('event_a', [$oReceiver, 'OnEvent2']);
$this->EventService_RegisterListener('event_a', ['Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1']);
$this->EventService_RegisterListener('event_a', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent2');
$this->EventService_RegisterListener('event_b', array($oReceiver, 'OnEvent1'));
$this->EventService_RegisterListener('event_b', array($oReceiver, 'OnEvent2'));
$this->EventService_RegisterListener('event_b', array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1'));
$this->EventService_RegisterListener('event_b', [$oReceiver, 'OnEvent1']);
$this->EventService_RegisterListener('event_b', [$oReceiver, 'OnEvent2']);
$this->EventService_RegisterListener('event_b', ['Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1']);
$this->EventService_RegisterListener('event_b', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent2');
self::$iEventCalls = 0;
@@ -163,13 +164,13 @@ class EventTest extends ItopDataTestCase
{
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -268,19 +269,18 @@ class EventTest extends ItopDataTestCase
}
public function testUnRegisterEventListener()
{
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event2', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -307,13 +307,13 @@ class EventTest extends ItopDataTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event2', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -335,13 +335,13 @@ class EventTest extends ItopDataTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
$sIdToRemove = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sIdToRemove = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sIdToRemove");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
$sId = $this->EventService_RegisterListener('event2', array($oReceiver, 'OnEvent1'));
$sId = $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent1']);
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -408,7 +408,6 @@ class TestClassesWithDebug
class TestEventReceiver extends TestClassesWithDebug
{
// Event callbacks
public function OnEvent1(EventData $oData)
{
@@ -458,4 +457,3 @@ class TestEventReceiver extends TestClassesWithDebug
EventTest::IncrementCallCount();
}
}

View File

@@ -36,9 +36,9 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
public function testShouldSelectTheRequestedItopClasses()
{
$this->GivenClassMap([
'Combodo\iTop\Application\UI\Base\Component\Alert\Alert' => APPROOT . '/sources/Application/UI/Base/Component/Alert/Alert.php',
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory' => APPROOT . '/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory' => APPROOT . '/sources/Application/UI/Base/Component/ButtonGroup/ButtonGroupUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\Alert\Alert' => APPROOT.'/sources/Application/UI/Base/Component/Alert/Alert.php',
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory' => APPROOT.'/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory' => APPROOT.'/sources/Application/UI/Base/Component/ButtonGroup/ButtonGroupUIBlockFactory.php',
]);
$this->AssertArraysHaveSameItems(
@@ -57,8 +57,8 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
{
$this->SetNonPublicProperty($this->oInterfaceDiscovery, 'bCheckInterfaceImplementation', false);
$this->GivenClassMap([
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory2' => APPROOT . '/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory2' => APPROOT . '/sources/Application/UI/Base/Component/ButtonGroup/ButtonGroupUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory2' => APPROOT.'/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory2' => APPROOT.'/sources/Application/UI/Base/Component/ButtonGroup/ButtonGroupUIBlockFactory.php',
]);
$this->AssertArraysHaveSameItems([], $this->oInterfaceDiscovery->FindItopClasses(iUIBlockFactory::class));
@@ -87,8 +87,8 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
public function testShouldExcludeAliases()
{
$this->GivenClassMap([
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory' => APPROOT . '/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'AlbertIsBlockingTheFactory' => APPROOT . '/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory' => APPROOT.'/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
'AlbertIsBlockingTheFactory' => APPROOT.'/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
]);
class_alias('Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory', 'AlbertIsBlockingTheFactory');
@@ -120,11 +120,13 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
MetaModel::GetConfig()->Set('developer_mode.interface_cache.enabled', true);
$this->assertGreaterThan(0, count($this->oInterfaceDiscovery->FindItopClasses(iUIBlockFactory::class)));
$this->AssertDirectoryListingEquals([
$this->AssertDirectoryListingEquals(
[
'autoload_classmaps.php',
'1ab1e62be3e9984a8176deeb20f049b1_iUIBlockFactory.php',
],
$this->sCacheRootDir.'/InterfaceDiscovery');
$this->sCacheRootDir.'/InterfaceDiscovery'
);
}
public function testShouldProduceStaticCacheForProduction()

View File

@@ -5,10 +5,8 @@
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\Service\Notification;
use Combodo\iTop\Core\Trigger\Enum\SubscriptionPolicy;
use Combodo\iTop\Service\Notification\NotificationsRepository;
use Combodo\iTop\Service\Notification\NotificationsService;
@@ -21,7 +19,8 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
* @package Combodo\iTop\Test\UnitTest\Service\Notification
* @covers \Combodo\iTop\Service\Notification\NotificationsService
*/
class NotificationsServiceTest extends ItopDataTestCase {
class NotificationsServiceTest extends ItopDataTestCase
{
public const CREATE_TEST_ORG = true;
/**
@@ -59,14 +58,12 @@ class NotificationsServiceTest extends ItopDataTestCase {
]);
$iActionNotificationID = $oActionNotification->GetKey();
$oService = NotificationsService::GetInstance();
// Case 1: Person hasn't received action so far, so it is implicitly subscribed by default
// - Assert
$this->assertTrue($oService->IsSubscribed($oTrigger, $oActionNotification, $oPerson));
// Case 2: Activate an action, the person should have an explicit subscription
// - Prepare
$oActionNotification->DoExecute($oTrigger, [
@@ -79,7 +76,6 @@ class NotificationsServiceTest extends ItopDataTestCase {
$this->assertEquals(1, $iSubscribedCount, "There should be 1 explicit subscription");
$this->assertTrue($oService->IsSubscribed($oTrigger, $oActionNotification, $oPerson));
// Case 3: Unsubscribe, person should have an explicit unsubscribe
// - Prepare
$oSubscription = NotificationsRepository::GetInstance()->SearchSubscribedSubscriptionsByTriggerContactAndAction($iTriggerID, $iActionNotificationID, $iPersonID)->Fetch();
@@ -93,4 +89,4 @@ class NotificationsServiceTest extends ItopDataTestCase {
$this->assertEquals(1, $iUnsubscribedCount, "There should be 1 explicit unsubscription");
$this->assertFalse($oService->IsSubscribed($oTrigger, $oActionNotification, $oPerson));
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -90,7 +91,7 @@ class RouterTest extends ItopDataTestCase
'object.modify',
[
'class' => 'Person',
'id' => 123
'id' => 123,
],
true,
],
@@ -247,7 +248,9 @@ class RouterTest extends ItopDataTestCase
// Generate corrupted cache manually
$sFaultyStatement = 'return 1;';
file_put_contents($sRoutesCacheFilePath, <<<PHP
file_put_contents(
$sRoutesCacheFilePath,
<<<PHP
<?php
{$sFaultyStatement}
@@ -427,4 +430,4 @@ PHP
],
];
}
}
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -14,8 +15,8 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
class TemporaryObjectManagerTest extends ItopDataTestCase
{
const USE_TRANSACTION = true;
const CREATE_TEST_ORG = false;
public const USE_TRANSACTION = true;
public const CREATE_TEST_ORG = false;
private TemporaryObjectConfig $oConfig;
private $oManager;
@@ -36,12 +37,12 @@ class TemporaryObjectManagerTest extends ItopDataTestCase
$oDescriptor = $this->oManager->CreateTemporaryObject($sTempId, 'FakedClass', -1, TemporaryObjectHelper::OPERATION_CREATE);
$this->assertNull( $oDescriptor);
$this->assertNull($oDescriptor);
$oOrg = $this->CreateTestOrganization();
$oDescriptor = $this->CreateTemporaryObject($sTempId, $oOrg, 3000, TemporaryObjectHelper::OPERATION_CREATE);
$this->assertNotNull( $oDescriptor);
$this->assertNotNull($oDescriptor);
}
public function testCancelAllTemporaryObjects()
@@ -156,7 +157,6 @@ class TemporaryObjectManagerTest extends ItopDataTestCase
$this->assertNull($oDeletedObject);
}
private function CreateTemporaryObject($sTempId, $oDBObject, int $iLifetime, string $sOperation)
{
$this->oConfig->SetConfigTemporaryLifetime($iLifetime);

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -15,8 +16,8 @@ use DBObject;
class TemporaryObjectRepositoryTest extends ItopDataTestCase
{
const USE_TRANSACTION = true;
const CREATE_TEST_ORG = false;
public const USE_TRANSACTION = true;
public const CREATE_TEST_ORG = false;
private TemporaryObjectConfig $oTemporaryObjectConfig;