-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathmock.dart
70 lines (58 loc) · 2.58 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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/cloud_functions_platform_interface.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart';
import '../../../firebase_core/firebase_core_platform_interface/test/test.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
typedef Callback = Function(MethodCall call);
const String kTestString = 'Hello World';
const String kBucket = 'gs://fake-storage-bucket-url.com';
const String kSecondaryBucket = 'gs://fake-storage-bucket-url-2.com';
void resetFirebaseCoreMocks() {
TestWidgetsFlutterBinding.ensureInitialized();
// Rest Firebase core apps & instance.
// TODO(Salakar): Is this an API core could provide for testing, e.g. Firebase.reset().
MethodChannelFirebase.appInstances = {};
MethodChannelFirebase.isCoreInitialized = false;
FirebasePlatform.instance = MethodChannelFirebase();
setupFirebaseCoreMocks();
}
class MockHttpsCallablePlatform extends HttpsCallablePlatform {
MockHttpsCallablePlatform(FirebaseFunctionsPlatform functions, String? origin,
String? name, HttpsCallableOptions options, Uri? uri)
: super(functions, origin, name, options, uri);
@override
Future<dynamic> call([dynamic parameters]) async {
// For testing purpose we return input data as output data.
return parameters;
}
}
class MockFirebaseFunctionsPlatform extends FirebaseFunctionsPlatform {
MockFirebaseFunctionsPlatform({FirebaseApp? app, required String region})
: super(app, region);
@override
HttpsCallablePlatform httpsCallable(
String? origin, String name, HttpsCallableOptions options) {
HttpsCallablePlatform httpsCallablePlatform =
MockHttpsCallablePlatform(this, origin, name, options, null);
return httpsCallablePlatform;
}
@override
HttpsCallablePlatform httpsCallableWithUri(
String? origin, Uri uri, HttpsCallableOptions options) {
HttpsCallablePlatform httpsCallablePlatform =
MockHttpsCallablePlatform(this, origin, null, options, uri);
return httpsCallablePlatform;
}
@override
FirebaseFunctionsPlatform delegateFor(
{FirebaseApp? app, required String region}) {
MockFirebaseFunctionsPlatform functionsPlatform =
MockFirebaseFunctionsPlatform(app: app, region: region);
return functionsPlatform;
}
}