[flutter_tools] replace MockFlutterVersion usage with fake where possible, move from context (#77390)

This commit is contained in:
Jonah Williams
2021-03-05 14:04:03 -08:00
committed by GitHub
parent db162a47f3
commit 721702717d
14 changed files with 153 additions and 168 deletions

View File

@@ -112,7 +112,7 @@ void testUsingContext(
Config: () => buildConfig(globals.fs),
DeviceManager: () => FakeDeviceManager(),
Doctor: () => FakeDoctor(globals.logger),
FlutterVersion: () => MockFlutterVersion(),
FlutterVersion: () => FakeFlutterVersion(),
HttpClient: () => FakeHttpClient.any(),
IOSSimulatorUtils: () {
final MockIOSSimulatorUtils mock = MockIOSSimulatorUtils();
@@ -377,8 +377,6 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
List<String> xcrunCommand() => <String>['xcrun'];
}
class MockFlutterVersion extends Mock implements FlutterVersion {}
class MockCrashReporter extends Mock implements CrashReporter {}
class LocalFileSystemBlockingSetCurrentDirectory extends LocalFileSystem {

View File

@@ -448,14 +448,67 @@ class FakePub extends Fake implements Pub {
}
class FakeFlutterVersion implements FlutterVersion {
@override
void fetchTagsAndUpdate() { }
FakeFlutterVersion({
this.channel = 'unknown',
this.dartSdkVersion = '12',
this.engineRevision = 'abcdefghijklmnopqrstuvwxyz',
this.engineRevisionShort = 'abcde',
this.repositoryUrl = 'https://github.com/flutter/flutter.git',
this.frameworkVersion = '0.0.0',
this.frameworkRevision = '11111111111111111111',
this.frameworkRevisionShort = '11111',
this.frameworkAge = '0 hours ago',
this.frameworkCommitDate = '12/01/01'
});
bool get didFetchTagsAndUpdate => _didFetchTagsAndUpdate;
bool _didFetchTagsAndUpdate = false;
bool get didCheckFlutterVersionFreshness => _didCheckFlutterVersionFreshness;
bool _didCheckFlutterVersionFreshness = false;
@override
String get channel => 'master';
final String channel;
@override
Future<void> checkFlutterVersionFreshness() async { }
final String dartSdkVersion;
@override
final String engineRevision;
@override
final String engineRevisionShort;
@override
final String repositoryUrl;
@override
final String frameworkVersion;
@override
final String frameworkRevision;
@override
final String frameworkRevisionShort;
@override
final String frameworkAge;
@override
final String frameworkCommitDate;
@override
String get frameworkDate => frameworkCommitDate;
@override
void fetchTagsAndUpdate() {
_didFetchTagsAndUpdate = true;
}
@override
Future<void> checkFlutterVersionFreshness() async {
_didCheckFlutterVersionFreshness = true;
}
@override
bool checkRevisionAncestry({String tentativeDescendantRevision, String tentativeAncestorRevision}) {
@@ -463,38 +516,13 @@ class FakeFlutterVersion implements FlutterVersion {
}
@override
String get dartSdkVersion => '12';
@override
String get engineRevision => '42.2';
@override
String get engineRevisionShort => '42';
GitTagVersion get gitTagVersion {
throw UnimplementedError();
}
@override
Future<void> ensureVersionFile() async { }
@override
String get frameworkAge => null;
@override
String get frameworkCommitDate => null;
@override
String get frameworkDate => null;
@override
String get frameworkRevision => null;
@override
String get frameworkRevisionShort => null;
@override
String get frameworkVersion => null;
@override
GitTagVersion get gitTagVersion => null;
@override
String getBranchName({bool redactUnknownBranches = false}) {
return 'master';
@@ -505,12 +533,9 @@ class FakeFlutterVersion implements FlutterVersion {
return 'v0.0.0';
}
@override
String get repositoryUrl => null;
@override
Map<String, Object> toJson() {
return null;
return <String, Object>{};
}
}

View File

@@ -15,6 +15,7 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
@@ -232,3 +233,4 @@ class MockStdIn extends Mock implements IOSink {
}
class MockStream extends Mock implements Stream<List<int>> {}
class MockFlutterVersion extends Mock implements FlutterVersion {}