N°7629 Deprecate utils::GetClassesForInterface in favor of InterfaceDiscovery::FindItopClasses

Improve caching strategy and robustness
This commit is contained in:
Romain Quetiez
2024-07-06 12:08:51 +02:00
parent 147aad9221
commit baf85e7a80
19 changed files with 845 additions and 112 deletions

View File

@@ -0,0 +1,73 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Service\InterfaceDiscovery;
use Combodo\iTop\Application\UI\Base\iUIBlockFactory;
use Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
class InterfaceDiscoveryTest extends ItopDataTestCase
{
protected function tearDown(): void
{
$this->SetNonPublicProperty(InterfaceDiscovery::GetInstance(), 'aForcedClassMap', null);
parent::tearDown();
}
public function testShouldSelectTheRequestedItopClasses()
{
$oInterfaceDiscoveryService = InterfaceDiscovery::GetInstance();
$this->GivenClassMap($oInterfaceDiscoveryService, [
'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(
[
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory',
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory',
],
$oInterfaceDiscoveryService->FindItopClasses(iUIBlockFactory::class)
);
}
public function testShouldExcludeSpecifiedDirectories()
{
$oInterfaceDiscoveryService = InterfaceDiscovery::GetInstance();
$this->GivenClassMap($oInterfaceDiscoveryService, [
'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(
[],
$oInterfaceDiscoveryService->FindItopClasses(iUIBlockFactory::class, ['Component/ButtonGroup', '/Alert/'])
);
}
public function testShouldExcludeAliases()
{
$oInterfaceDiscoveryService = InterfaceDiscovery::GetInstance();
$this->GivenClassMap($oInterfaceDiscoveryService, [
'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');
$this->AssertArraysHaveSameItems(
[
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory',
],
$oInterfaceDiscoveryService->FindItopClasses(iUIBlockFactory::class)
);
}
private function GivenClassMap(InterfaceDiscovery $oInterfaceDiscoveryService, array $aClassMap): void
{
$this->SetNonPublicProperty($oInterfaceDiscoveryService, 'aForcedClassMap', $aClassMap);
}
}