forked from fa/breadcrumb-the-shire
Align CustomField-Schicht mit core/Repository/Access-Muster. Vier Repositories (Tenant-Definition, Tenant-Option, User-Value, User-Value-Option) bekommen je ein Interface, werden von static auf instance umgestellt und ueber CustomFieldRepositoryFactory injiziert. TenantCustomFieldService und UserCustomFieldValueService injizieren die Repository-Interfaces statt statisch aufzurufen. CustomFieldServicesFactory reicht Instanzen durch. AddressBookService (Modul) bekommt TenantCustomFieldOptionRepositoryInterface per Container — Interface-Kopplung verbessert Modul-Isolation gegenueber dem vorherigen statischen Aufruf. Kein Verhaltenswechsel, keine SQL-Aenderung, keine Service-Signatur-Aenderung. Alle tenant_id-Parameter erhalten (GR-SEC-009, Security-Review SR-002). Oeffnet den Weg fuer Cluster B1 (TenantCustomFieldService-Tests) und B2 (UserCustomFieldValueService-Tests), die nun mit createMock() moeglich sind. Nebenbei zwei PHPStan-Folge-Findings korrigiert: - Veralteter Ignore-Eintrag fuer findById aus phpstan-baseline.neon entfernt - Redundanter is_array-Check in TenantCustomFieldOptionRepository entfernt (durch typisierte Interface-Signatur abgedeckt) Gates: QG-001 (1945 Tests, 28581 Assertions) / QG-002 / QG-003 / QG-006 pass. Workflow: .agents/runs/CUSTOMFIELD-DI-REFACTOR-001/ Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
3.3 KiB
PHP
93 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Module\AddressBook\Service;
|
|
|
|
use MintyPHP\Module\AddressBook\Service\AddressBookService;
|
|
use MintyPHP\Repository\CustomField\TenantCustomFieldOptionRepositoryInterface;
|
|
use MintyPHP\Service\Access\RoleService;
|
|
use MintyPHP\Service\CustomField\UserCustomFieldValueService;
|
|
use MintyPHP\Service\Org\DepartmentService;
|
|
use MintyPHP\Service\Tenant\TenantScopeService;
|
|
use MintyPHP\Service\Tenant\TenantService;
|
|
use MintyPHP\Service\User\UserAccountService;
|
|
use MintyPHP\Service\User\UserAvatarService;
|
|
use MintyPHP\Service\User\UserProfileViewService;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AddressBookServiceTest extends TestCase
|
|
{
|
|
public function testBuildIndexContextBuildsTenantDepartmentMapForGlobalScope(): void
|
|
{
|
|
$userAccountService = $this->createMock(UserAccountService::class);
|
|
$tenantService = $this->createMock(TenantService::class);
|
|
$departmentService = $this->createMock(DepartmentService::class);
|
|
$roleService = $this->createMock(RoleService::class);
|
|
$scopeGateway = $this->createMock(TenantScopeService::class);
|
|
$customFieldGateway = $this->createMock(UserCustomFieldValueService::class);
|
|
$avatarService = $this->createMock(UserAvatarService::class);
|
|
$userProfileViewService = $this->createMock(UserProfileViewService::class);
|
|
$tenantCustomFieldOptionRepository = $this->createMock(TenantCustomFieldOptionRepositoryInterface::class);
|
|
|
|
$scopeGateway
|
|
->expects($this->once())
|
|
->method('getUserTenantIds')
|
|
->with(7)
|
|
->willReturn([]);
|
|
$tenantService
|
|
->expects($this->once())
|
|
->method('list')
|
|
->willReturn([
|
|
['id' => 1, 'uuid' => 'tenant-a', 'description' => 'Tenant A'],
|
|
['id' => 2, 'uuid' => 'tenant-b', 'description' => 'Tenant B'],
|
|
]);
|
|
$scopeGateway
|
|
->expects($this->exactly(2))
|
|
->method('isStrict')
|
|
->willReturn(false);
|
|
$departmentService
|
|
->expects($this->once())
|
|
->method('list')
|
|
->willReturn([
|
|
['id' => 10, 'tenant_id' => 1, 'description' => 'Sales'],
|
|
['id' => 20, 'tenant_id' => 2, 'description' => 'Support'],
|
|
]);
|
|
$departmentService
|
|
->expects($this->never())
|
|
->method('listByTenantIds');
|
|
$roleService
|
|
->expects($this->once())
|
|
->method('listActive')
|
|
->willReturn([]);
|
|
|
|
$customFieldGateway
|
|
->expects($this->once())
|
|
->method('extractCustomFieldFilterSpec')
|
|
->with([], 7)
|
|
->willReturn([
|
|
'definitions' => [],
|
|
'query' => [],
|
|
]);
|
|
$service = new AddressBookService(
|
|
$userAccountService,
|
|
$tenantService,
|
|
$departmentService,
|
|
$roleService,
|
|
$scopeGateway,
|
|
$customFieldGateway,
|
|
$avatarService,
|
|
$userProfileViewService,
|
|
$tenantCustomFieldOptionRepository
|
|
);
|
|
|
|
$context = $service->buildIndexContext(7, []);
|
|
|
|
$this->assertSame(
|
|
[
|
|
'tenant-a' => ['10'],
|
|
'tenant-b' => ['20'],
|
|
],
|
|
$context['tenantDepartmentMap']
|
|
);
|
|
}
|
|
}
|