Unverified Commit c9323bdc authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Convert cocoapods_validator_test to testWithoutContext (#53177)

parent 70c651b0
......@@ -106,7 +106,10 @@ Future<T> runInContext<T>(
platform: globals.platform,
),
CocoaPods: () => CocoaPods(),
CocoaPodsValidator: () => const CocoaPodsValidator(),
CocoaPodsValidator: () => CocoaPodsValidator(
globals.cocoaPods,
globals.userMessages,
),
Config: () => Config(
Config.kFlutterSettings,
fileSystem: globals.fs,
......
......@@ -28,6 +28,7 @@ import 'ios/ios_workflow.dart';
import 'ios/plist_parser.dart';
import 'ios/simulators.dart';
import 'ios/xcodeproj.dart';
import 'macos/cocoapods.dart';
import 'macos/xcode.dart';
import 'persistent_tool_state.dart';
import 'reporting/reporting.dart';
......@@ -71,6 +72,7 @@ Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
AndroidStudio get androidStudio => context.get<AndroidStudio>();
AndroidSdk get androidSdk => context.get<AndroidSdk>();
CocoaPods get cocoaPods => context.get<CocoaPods>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>();
FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>();
IOSDeploy get iosDeploy => context.get<IOSDeploy>();
......
......@@ -10,7 +10,6 @@ import '../globals.dart' as globals;
import '../ios/xcodeproj.dart';
import '../plugins.dart';
import '../project.dart';
import 'cocoapods.dart';
/// For a given build, determines whether dependencies have changed since the
/// last call to processPods, then calls processPods with that information.
......@@ -33,7 +32,7 @@ Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject, String buildDir
properties: <String, String>{},
);
final bool didPodInstall = await cocoaPods.processPods(
final bool didPodInstall = await globals.cocoaPods.processPods(
xcodeProject: xcodeProject,
engineDir: flutterFrameworkDir(buildMode),
dependenciesChanged: !fingerprinter.doesFingerprintMatch(),
......
......@@ -8,7 +8,6 @@ import 'package:file/file.dart';
import 'package:meta/meta.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
......@@ -45,8 +44,6 @@ const String cocoaPodsUpgradeInstructions = '''
const String podfileMigrationInstructions = '''
rm ios/Podfile''';
CocoaPods get cocoaPods => context.get<CocoaPods>();
/// Result of evaluating the CocoaPods installation.
enum CocoaPodsStatus {
/// iOS plugins will not work, installation required.
......
......@@ -12,42 +12,51 @@ import 'cocoapods.dart';
CocoaPodsValidator get cocoapodsValidator => context.get<CocoaPodsValidator>();
class CocoaPodsValidator extends DoctorValidator {
const CocoaPodsValidator() : super('CocoaPods subvalidator');
CocoaPodsValidator(
CocoaPods cocoaPods,
UserMessages userMessages,
) : _cocoaPods = cocoaPods,
_userMessages = userMessages,
super('CocoaPods subvalidator');
final CocoaPods _cocoaPods;
final UserMessages _userMessages;
@override
Future<ValidationResult> validate() async {
final List<ValidationMessage> messages = <ValidationMessage>[];
final CocoaPodsStatus cocoaPodsStatus = await cocoaPods
.evaluateCocoaPodsInstallation;
final CocoaPodsStatus cocoaPodsStatus = await _cocoaPods
.evaluateCocoaPodsInstallation;
ValidationType status = ValidationType.installed;
if (cocoaPodsStatus == CocoaPodsStatus.recommended) {
if (await cocoaPods.isCocoaPodsInitialized) {
messages.add(ValidationMessage(userMessages.cocoaPodsVersion(await cocoaPods.cocoaPodsVersionText)));
if (await _cocoaPods.isCocoaPodsInitialized) {
messages.add(ValidationMessage(_userMessages.cocoaPodsVersion(await _cocoaPods.cocoaPodsVersionText)));
} else {
status = ValidationType.partial;
messages.add(ValidationMessage.error(userMessages.cocoaPodsUninitialized(noCocoaPodsConsequence)));
messages.add(ValidationMessage.error(_userMessages.cocoaPodsUninitialized(noCocoaPodsConsequence)));
}
} else {
if (cocoaPodsStatus == CocoaPodsStatus.notInstalled) {
status = ValidationType.missing;
messages.add(ValidationMessage.error(
userMessages.cocoaPodsMissing(noCocoaPodsConsequence, cocoaPodsInstallInstructions)));
_userMessages.cocoaPodsMissing(noCocoaPodsConsequence, cocoaPodsInstallInstructions)));
} else if (cocoaPodsStatus == CocoaPodsStatus.brokenInstall) {
status = ValidationType.missing;
messages.add(ValidationMessage.error(
userMessages.cocoaPodsBrokenInstall(brokenCocoaPodsConsequence, cocoaPodsInstallInstructions)));
_userMessages.cocoaPodsBrokenInstall(brokenCocoaPodsConsequence, cocoaPodsInstallInstructions)));
} else if (cocoaPodsStatus == CocoaPodsStatus.unknownVersion) {
status = ValidationType.partial;
messages.add(ValidationMessage.hint(
userMessages.cocoaPodsUnknownVersion(unknownCocoaPodsConsequence, cocoaPodsUpgradeInstructions)));
_userMessages.cocoaPodsUnknownVersion(unknownCocoaPodsConsequence, cocoaPodsUpgradeInstructions)));
} else {
status = ValidationType.partial;
final String currentVersionText = await cocoaPods.cocoaPodsVersionText;
final String currentVersionText = await _cocoaPods.cocoaPodsVersionText;
messages.add(ValidationMessage.hint(
userMessages.cocoaPodsOutdated(currentVersionText, cocoaPods.cocoaPodsRecommendedVersion, noCocoaPodsConsequence, cocoaPodsUpgradeInstructions)));
_userMessages.cocoaPodsOutdated(currentVersionText, _cocoaPods.cocoaPodsRecommendedVersion, noCocoaPodsConsequence, cocoaPodsUpgradeInstructions)));
}
}
......
......@@ -15,7 +15,6 @@ import 'convert.dart';
import 'dart/package_map.dart';
import 'features.dart';
import 'globals.dart' as globals;
import 'macos/cocoapods.dart';
import 'platform_plugins.dart';
import 'project.dart';
import 'windows/property_sheet.dart';
......@@ -1058,12 +1057,12 @@ void refreshPluginsList(FlutterProject project, {bool checkProjects = false}) {
if (changed || legacyChanged) {
createPluginSymlinks(project, force: true);
if (!checkProjects || project.ios.existsSync()) {
cocoaPods.invalidatePodInstallOutput(project.ios);
globals.cocoaPods.invalidatePodInstallOutput(project.ios);
}
// TODO(stuartmorgan): Potentially add checkProjects once a decision has
// made about how to handle macOS in existing projects.
if (project.macos.existsSync()) {
cocoaPods.invalidatePodInstallOutput(project.macos);
globals.cocoaPods.invalidatePodInstallOutput(project.macos);
}
}
}
......@@ -1097,14 +1096,13 @@ Future<void> injectPlugins(FlutterProject project, {bool checkProjects = false})
}
for (final XcodeBasedProject subproject in <XcodeBasedProject>[project.ios, project.macos]) {
if (!project.isModule && (!checkProjects || subproject.existsSync())) {
final CocoaPods cocoaPods = CocoaPods();
if (plugins.isNotEmpty) {
await cocoaPods.setupPodfile(subproject);
await globals.cocoaPods.setupPodfile(subproject);
}
/// The user may have a custom maintained Podfile that they're running `pod install`
/// on themselves.
else if (subproject.podfile.existsSync() && subproject.podfileLock.existsSync()) {
cocoaPods.addPodsDependencyToFlutterXcconfig(subproject);
globals.cocoaPods.addPodsDependencyToFlutterXcconfig(subproject);
}
}
}
......
......@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/dart.dart';
import 'package:flutter_tools/src/build_system/targets/macos.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/macos/cocoapods.dart';
import 'package:flutter_tools/src/macos/xcode.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
......@@ -193,7 +192,6 @@ void main() {
}
class MockPlatform extends Mock implements Platform {}
class MockCocoaPods extends Mock implements CocoaPods {}
class MockProcessManager extends Mock implements ProcessManager {}
class MockGenSnapshot extends Mock implements GenSnapshot {}
class MockXcode extends Mock implements Xcode {}
......
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/macos/cocoapods.dart';
import 'package:flutter_tools/src/macos/cocoapods_validator.dart';
import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
group('CocoaPods validation', () {
......@@ -22,44 +22,36 @@ void main() {
when(cocoaPods.cocoaPodsVersionText).thenAnswer((_) async => '1.8.0');
});
testUsingContext('Emits installed status when CocoaPods is installed', () async {
const CocoaPodsValidator workflow = CocoaPodsValidator();
testWithoutContext('Emits installed status when CocoaPods is installed', () async {
final CocoaPodsValidator workflow = CocoaPodsValidator(cocoaPods, UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.installed);
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
testUsingContext('Emits missing status when CocoaPods is not installed', () async {
testWithoutContext('Emits missing status when CocoaPods is not installed', () async {
when(cocoaPods.evaluateCocoaPodsInstallation)
.thenAnswer((_) async => CocoaPodsStatus.notInstalled);
const CocoaPodsValidator workflow = CocoaPodsValidator();
final CocoaPodsValidator workflow = CocoaPodsValidator(cocoaPods, UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.missing);
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
testUsingContext('Emits partial status when CocoaPods is installed with unknown version', () async {
testWithoutContext('Emits partial status when CocoaPods is installed with unknown version', () async {
when(cocoaPods.evaluateCocoaPodsInstallation)
.thenAnswer((_) async => CocoaPodsStatus.unknownVersion);
const CocoaPodsValidator workflow = CocoaPodsValidator();
final CocoaPodsValidator workflow = CocoaPodsValidator(cocoaPods, UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
testUsingContext('Emits partial status when CocoaPods is not initialized', () async {
testWithoutContext('Emits partial status when CocoaPods is not initialized', () async {
when(cocoaPods.isCocoaPodsInitialized).thenAnswer((_) async => false);
const CocoaPodsValidator workflow = CocoaPodsValidator();
final CocoaPodsValidator workflow = CocoaPodsValidator(cocoaPods, UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
testUsingContext('Emits partial status when CocoaPods version is too low', () async {
testWithoutContext('Emits partial status when CocoaPods version is too low', () async {
when(cocoaPods.evaluateCocoaPodsInstallation)
.thenAnswer((_) async => CocoaPodsStatus.belowRecommendedVersion);
const String currentVersion = '1.4.0';
......@@ -68,7 +60,7 @@ void main() {
const String recommendedVersion = '1.8.0';
when(cocoaPods.cocoaPodsRecommendedVersion)
.thenAnswer((_) => recommendedVersion);
const CocoaPodsValidator workflow = CocoaPodsValidator();
final CocoaPodsValidator workflow = CocoaPodsValidator(cocoaPods, UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
expect(result.messages.length, 1);
......@@ -76,8 +68,6 @@ void main() {
expect(message.type, ValidationMessageType.hint);
expect(message.message, contains('CocoaPods $currentVersion out of date'));
expect(message.message, contains('($recommendedVersion is recommended)'));
}, overrides: <Type, Generator>{
CocoaPods: () => cocoaPods,
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment