refactor(arch): enforce gateway compliance and remove service-wrapping gateways

This commit is contained in:
2026-03-13 11:31:33 +01:00
parent 082fa4c9a5
commit 892da0048d
96 changed files with 1117 additions and 1060 deletions

View File

@@ -5,7 +5,6 @@ namespace MintyPHP\Tests\Service\Tenant;
use MintyPHP\Repository\Org\DepartmentRepository;
use MintyPHP\Repository\Tenant\TenantRepository;
use MintyPHP\Repository\Tenant\UserTenantRepository;
use MintyPHP\Service\Access\PermissionGateway;
use MintyPHP\Service\Access\PermissionService;
use MintyPHP\Service\Tenant\TenantScopeService;
use PHPUnit\Framework\TestCase;
@@ -34,8 +33,8 @@ class TenantScopeServiceTest extends TestCase
return [];
});
$permissionGateway = $this->createMock(PermissionGateway::class);
$permissionGateway->method('userHas')
$permissionService = $this->createMock(PermissionService::class);
$permissionService->method('userHas')
->willReturnCallback(static function (int $userId, string $permission) use (&$checkedPermissions): bool {
$checkedPermissions[] = $permission;
if ($userId !== 10) {
@@ -49,7 +48,7 @@ class TenantScopeServiceTest extends TestCase
$tenantRepository,
$departmentRepository,
$userTenantRepository,
$permissionGateway
$permissionService
);
$this->assertFalse($service->hasGlobalAccess(10));
@@ -66,16 +65,16 @@ class TenantScopeServiceTest extends TestCase
$tenantRepository = $this->createMock(TenantRepository::class);
$departmentRepository = $this->createMock(DepartmentRepository::class);
$userTenantRepository = $this->createMock(UserTenantRepository::class);
$permissionGateway = $this->createMock(PermissionGateway::class);
$permissionService = $this->createMock(PermissionService::class);
$permissionGateway->method('userHas')
$permissionService->method('userHas')
->willReturnCallback(static fn (int $userId, string $permission): bool => $userId === 77 && $permission === PermissionService::TENANT_SCOPE_GLOBAL);
$service = new TenantScopeService(
$tenantRepository,
$departmentRepository,
$userTenantRepository,
$permissionGateway
$permissionService
);
$this->assertTrue($service->hasGlobalAccess(77));
@@ -97,15 +96,15 @@ class TenantScopeServiceTest extends TestCase
$userTenantRepository = $this->createMock(UserTenantRepository::class);
$userTenantRepository->expects($this->never())->method('listTenantIdsByUserId');
$permissionGateway = $this->createMock(PermissionGateway::class);
$permissionGateway->method('userHas')
$permissionService = $this->createMock(PermissionService::class);
$permissionService->method('userHas')
->willReturnCallback(static fn (int $userId, string $permission): bool => $userId === 55 && $permission === PermissionService::TENANT_SCOPE_GLOBAL);
$service = new TenantScopeService(
$tenantRepository,
$departmentRepository,
$userTenantRepository,
$permissionGateway
$permissionService
);
$this->assertSame([1, 3], $service->getUserTenantIds(55));
@@ -127,14 +126,14 @@ class TenantScopeServiceTest extends TestCase
->with(88)
->willReturn([2, 4, 4]);
$permissionGateway = $this->createMock(PermissionGateway::class);
$permissionGateway->method('userHas')->willReturn(false);
$permissionService = $this->createMock(PermissionService::class);
$permissionService->method('userHas')->willReturn(false);
$service = new TenantScopeService(
$tenantRepository,
$departmentRepository,
$userTenantRepository,
$permissionGateway
$permissionService
);
$this->assertSame([2], $service->getUserTenantIds(88));