Skip to content

Commit 4f480f1

Browse files
committed
use fake platform interface for test
1 parent 40b5c01 commit 4f480f1

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ClientIO extends ClientBase with ClientMixin {
8080
@override
8181
String get endPoint => _endPoint;
8282

83-
Future<Directory> getCookiePath() async {
83+
Future<Directory> _getCookiePath() async {
8484
final directory = await getApplicationDocumentsDirectory();
8585
final path = directory.path;
8686
final Directory dir = Directory('$path/cookies');
@@ -133,7 +133,7 @@ class ClientIO extends ClientBase with ClientMixin {
133133
Future init() async {
134134
if(_initProgress) return;
135135
_initProgress = true;
136-
final Directory cookieDir = await getCookiePath();
136+
final Directory cookieDir = await _getCookiePath();
137137
_cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path));
138138
_interceptors.add(CookieManager(_cookieJar));
139139

templates/flutter/pubspec.yaml.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121
universal_html: ^2.0.8
2222
2323
dev_dependencies:
24+
path_provider_platform_interface: ^2.0.5
2425
flutter_lints: ^2.0.1
2526
flutter_test:
2627
sdk: flutter

tests/languages/flutter/tests.dart

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,60 @@
11
import 'package:flutter/material.dart';
2+
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
3+
24
import '../lib/packageName.dart';
35
import '../lib/client_io.dart';
46
import '../lib/models.dart';
57
import 'dart:io';
68

7-
class MockClient extends ClientIO {
8-
Future<Directory> getCookiePath() async {
9-
final dir = Directory('cookies');
10-
await dir.create();
11-
return dir;
9+
class FakePathProvider extends PathProviderPlatform {
10+
@override
11+
Future<String?> getTemporaryPath() async {
12+
return '.';
13+
}
14+
15+
@override
16+
Future<String?> getApplicationSupportPath() async {
17+
return '.';
18+
}
19+
20+
@override
21+
Future<String?> getLibraryPath() async {
22+
return '.';
23+
}
24+
25+
@override
26+
Future<String?> getApplicationDocumentsPath() async {
27+
return '.';
28+
}
29+
30+
@override
31+
Future<String?> getExternalStoragePath() async {
32+
return '.';
33+
}
34+
35+
@override
36+
Future<List<String>?> getExternalCachePaths() async {
37+
return <String>['.'];
38+
}
39+
40+
@override
41+
Future<List<String>?> getExternalStoragePaths({
42+
StorageDirectory? type,
43+
}) async {
44+
return <String>['.'];
45+
}
46+
47+
@override
48+
Future<String?> getDownloadsPath() async {
49+
return '.';
1250
}
1351
}
1452

53+
1554
void main() async {
1655
WidgetsFlutterBinding.ensureInitialized();
17-
18-
Client client = MockClient();
56+
PathProviderPlatform.instance = FakePathProvider();
57+
Client client = Client();
1958
Foo foo = Foo(client);
2059
Bar bar = Bar(client);
2160
General general = General(client);

0 commit comments

Comments
 (0)