Unverified Commit 675fd554 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Replace MockXcode with Xcode.test in unit tests (#74777)

parent c6a428d5
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:file/memory.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -229,25 +230,78 @@ List<String> _xcodeBuildSettingsLines({ ...@@ -229,25 +230,78 @@ List<String> _xcodeBuildSettingsLines({
/// Interpreter of Xcode projects. /// Interpreter of Xcode projects.
class XcodeProjectInterpreter { class XcodeProjectInterpreter {
XcodeProjectInterpreter({ factory XcodeProjectInterpreter({
@required Platform platform, @required Platform platform,
@required ProcessManager processManager, @required ProcessManager processManager,
@required Logger logger, @required Logger logger,
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required Terminal terminal, @required Terminal terminal,
@required Usage usage, @required Usage usage,
}) {
return XcodeProjectInterpreter._(
platform: platform,
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
terminal: terminal,
usage: usage,
);
}
XcodeProjectInterpreter._({
@required Platform platform,
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required Terminal terminal,
@required Usage usage,
int majorVersion,
int minorVersion,
int patchVersion,
}) : _platform = platform, }) : _platform = platform,
_fileSystem = fileSystem, _fileSystem = fileSystem,
_terminal = terminal, _terminal = terminal,
_logger = logger, _logger = logger,
_processUtils = ProcessUtils(logger: logger, processManager: processManager), _processUtils = ProcessUtils(logger: logger, processManager: processManager),
_operatingSystemUtils = OperatingSystemUtils( _operatingSystemUtils = OperatingSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
logger: logger, logger: logger,
platform: platform, platform: platform,
processManager: processManager, processManager: processManager,
), ),
_usage = usage; _majorVersion = majorVersion,
_minorVersion = minorVersion,
_patchVersion = patchVersion,
_usage = usage;
/// Create an [XcodeProjectInterpreter] for testing.
///
/// Defaults to installed with sufficient version,
/// a memory file system, fake platform, buffer logger,
/// test [Usage], and test [Terminal].
/// Set [majorVersion] to null to simulate Xcode not being installed.
factory XcodeProjectInterpreter.test({
@required ProcessManager processManager,
int majorVersion = 1000,
int minorVersion = 0,
int patchVersion = 0,
}) {
final Platform platform = FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{},
);
return XcodeProjectInterpreter._(
fileSystem: MemoryFileSystem.test(),
platform: platform,
processManager: processManager,
usage: Usage.test(),
logger: BufferLogger.test(),
terminal: Terminal.test(),
majorVersion: majorVersion,
minorVersion: minorVersion,
patchVersion: patchVersion,
);
}
final Platform _platform; final Platform _platform;
final FileSystem _fileSystem; final FileSystem _fileSystem;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'package:file/memory.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -55,6 +56,30 @@ class Xcode { ...@@ -55,6 +56,30 @@ class Xcode {
_processUtils = _processUtils =
ProcessUtils(logger: logger, processManager: processManager); ProcessUtils(logger: logger, processManager: processManager);
/// Create an [Xcode] for testing.
///
/// Defaults to a memory file system, fake platform,
/// buffer logger, and test [XcodeProjectInterpreter].
@visibleForTesting
factory Xcode.test({
@required ProcessManager processManager,
XcodeProjectInterpreter xcodeProjectInterpreter,
Platform platform,
FileSystem fileSystem,
}) {
platform ??= FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{},
);
return Xcode(
platform: platform,
processManager: processManager,
fileSystem: fileSystem ?? MemoryFileSystem.test(),
logger: BufferLogger.test(),
xcodeProjectInterpreter: xcodeProjectInterpreter ?? XcodeProjectInterpreter.test(processManager: processManager),
);
}
final Platform _platform; final Platform _platform;
final ProcessUtils _processUtils; final ProcessUtils _processUtils;
final FileSystem _fileSystem; final FileSystem _fileSystem;
...@@ -78,12 +103,7 @@ class Xcode { ...@@ -78,12 +103,7 @@ class Xcode {
return _xcodeSelectPath; return _xcodeSelectPath;
} }
bool get isInstalled { bool get isInstalled => _xcodeProjectInterpreter.isInstalled;
if (xcodeSelectPath == null || xcodeSelectPath.isEmpty) {
return false;
}
return _xcodeProjectInterpreter.isInstalled;
}
Version get currentVersion => Version( Version get currentVersion => Version(
_xcodeProjectInterpreter.majorVersion, _xcodeProjectInterpreter.majorVersion,
......
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