createMock(UserAccountService::class); $userAssignmentService = $this->createMock(UserAssignmentService::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); $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, $userAssignmentService, $tenantService, $departmentService, $roleService, $scopeGateway, $customFieldGateway, $avatarService ); $context = $service->buildIndexContext(7, []); $this->assertSame( [ 'tenant-a' => ['10'], 'tenant-b' => ['20'], ], $context['tenantDepartmentMap'] ); } }