createMock(UserAccountService::class); $userAssignmentService = $this->createMock(UserAssignmentService::class); $directoryGateway = $this->createMock(AddressBookDirectoryGateway::class); $customFieldGateway = $this->createMock(AddressBookCustomFieldGateway::class); $avatarGateway = $this->createMock(AddressBookAvatarGateway::class); $directoryGateway ->expects($this->once()) ->method('getUserTenantIds') ->with(7) ->willReturn([]); $directoryGateway ->expects($this->once()) ->method('listTenants') ->willReturn([ ['id' => 1, 'uuid' => 'tenant-a', 'description' => 'Tenant A'], ['id' => 2, 'uuid' => 'tenant-b', 'description' => 'Tenant B'], ]); $directoryGateway ->expects($this->exactly(2)) ->method('isStrictScope') ->willReturn(false); $directoryGateway ->expects($this->once()) ->method('listDepartments') ->willReturn([ ['id' => 10, 'tenant_id' => 1, 'description' => 'Sales'], ['id' => 20, 'tenant_id' => 2, 'description' => 'Support'], ]); $directoryGateway ->expects($this->never()) ->method('listDepartmentsByTenantIds'); $directoryGateway ->expects($this->once()) ->method('listActiveRoles') ->willReturn([]); $customFieldGateway ->expects($this->once()) ->method('extractFilterSpec') ->with([], 7) ->willReturn([ 'definitions' => [], 'query' => [], ]); $customFieldGateway ->expects($this->once()) ->method('listOptionsByDefinitionIds') ->with([], true) ->willReturn([]); $service = new AddressBookService( $userAccountService, $userAssignmentService, $directoryGateway, $customFieldGateway, $avatarGateway ); $context = $service->buildIndexContext(7, []); $this->assertSame( [ 'tenant-a' => ['10'], 'tenant-b' => ['20'], ], $context['tenantDepartmentMap'] ); } }