-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathmock.dart
43 lines (36 loc) · 1.59 KB
/
mock.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// ignore_for_file: require_trailing_commas
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:cloud_functions_platform_interface/src/firebase_functions_exception.dart';
import 'package:cloud_functions_platform_interface/src/method_channel/method_channel_firebase_functions.dart';
import '../../../firebase_core/firebase_core_platform_interface/test/test.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
typedef MethodCallCallback = dynamic Function(MethodCall methodCall);
typedef Callback = Function(MethodCall call);
int mockHandleId = 0;
int get nextMockHandleId => mockHandleId++;
void setupFirebaseFunctionsMocks([Callback? customHandlers]) {
TestWidgetsFlutterBinding.ensureInitialized();
setupFirebaseCoreMocks();
}
void handleMethodCall(MethodCallCallback methodCallCallback) =>
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(MethodChannelFirebaseFunctions.channel,
(call) async {
return await methodCallCallback(call);
});
Future<void> testExceptionHandling(String type, Function testMethod) async {
try {
await testMethod();
} on FirebaseFunctionsException catch (_) {
if (type == 'PLATFORM' || type == 'EXCEPTION') {
return;
}
fail(
'testExceptionHandling: $testMethod threw unexpected FirebaseFunctionsException');
} catch (e) {
fail('testExceptionHandling: $testMethod threw invalid exception $e');
}
}