1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

🏗 Fake shell in use

This commit is contained in:
2022-10-04 19:39:34 +02:00
parent 2c25bcbdb5
commit 0b33116eb0
5 changed files with 52 additions and 7 deletions

View File

@ -59,6 +59,8 @@
C40C7F2927721FF600DDDCDC /* ActivePhpInstallation+Checks.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */; }; C40C7F2927721FF600DDDCDC /* ActivePhpInstallation+Checks.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */; };
C40C7F3027722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; }; C40C7F3027722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; };
C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; }; C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40C7F2F27722E8D00DDDCDC /* Logger.swift */; };
C40F505528ECA64E004AD45B /* Testables.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40F505428ECA64E004AD45B /* Testables.swift */; };
C40F505628ECA64E004AD45B /* Testables.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40F505428ECA64E004AD45B /* Testables.swift */; };
C40FE737282ABA4F00A302C2 /* AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE736282ABA4F00A302C2 /* AppVersion.swift */; }; C40FE737282ABA4F00A302C2 /* AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE736282ABA4F00A302C2 /* AppVersion.swift */; };
C40FE738282ABA4F00A302C2 /* AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE736282ABA4F00A302C2 /* AppVersion.swift */; }; C40FE738282ABA4F00A302C2 /* AppVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE736282ABA4F00A302C2 /* AppVersion.swift */; };
C40FE73B282ABB2E00A302C2 /* AppVersionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE739282ABB2E00A302C2 /* AppVersionTest.swift */; }; C40FE73B282ABB2E00A302C2 /* AppVersionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C40FE739282ABB2E00A302C2 /* AppVersionTest.swift */; };
@ -364,6 +366,7 @@
C40C7F1D2772136000DDDCDC /* PhpEnv.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpEnv.swift; sourceTree = "<group>"; }; C40C7F1D2772136000DDDCDC /* PhpEnv.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpEnv.swift; sourceTree = "<group>"; };
C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ActivePhpInstallation+Checks.swift"; sourceTree = "<group>"; }; C40C7F2727721FF600DDDCDC /* ActivePhpInstallation+Checks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ActivePhpInstallation+Checks.swift"; sourceTree = "<group>"; };
C40C7F2F27722E8D00DDDCDC /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; }; C40C7F2F27722E8D00DDDCDC /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
C40F505428ECA64E004AD45B /* Testables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Testables.swift; sourceTree = "<group>"; };
C40FE736282ABA4F00A302C2 /* AppVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVersion.swift; sourceTree = "<group>"; }; C40FE736282ABA4F00A302C2 /* AppVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVersion.swift; sourceTree = "<group>"; };
C40FE739282ABB2E00A302C2 /* AppVersionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVersionTest.swift; sourceTree = "<group>"; }; C40FE739282ABB2E00A302C2 /* AppVersionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVersionTest.swift; sourceTree = "<group>"; };
C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomebrewPackage.swift; sourceTree = "<group>"; }; C412E5FB25700D5300A1FB67 /* HomebrewPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomebrewPackage.swift; sourceTree = "<group>"; };
@ -883,6 +886,7 @@
C46EBC4628DB9644007ACC74 /* SystemShell.swift */, C46EBC4628DB9644007ACC74 /* SystemShell.swift */,
C46EBC4928DB966A007ACC74 /* TestableShell.swift */, C46EBC4928DB966A007ACC74 /* TestableShell.swift */,
C46EBC4328DB95F0007ACC74 /* Shellable.swift */, C46EBC4328DB95F0007ACC74 /* Shellable.swift */,
C40F505428ECA64E004AD45B /* Testables.swift */,
); );
path = Next; path = Next;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1488,6 +1492,7 @@
C4C3ED412783497000AB15D8 /* MainMenu+Startup.swift in Sources */, C4C3ED412783497000AB15D8 /* MainMenu+Startup.swift in Sources */,
C40508AF28ADA23D008FAC1F /* NoDomainResultsView.swift in Sources */, C40508AF28ADA23D008FAC1F /* NoDomainResultsView.swift in Sources */,
C4D89BC62783C99400A02B68 /* ComposerJson.swift in Sources */, C4D89BC62783C99400A02B68 /* ComposerJson.swift in Sources */,
C40F505528ECA64E004AD45B /* Testables.swift in Sources */,
C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */, C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */,
C42E3BF428A9BF5100AFECFC /* LegacyShell+PATH.swift in Sources */, C42E3BF428A9BF5100AFECFC /* LegacyShell+PATH.swift in Sources */,
C42337A3281F19F000459A48 /* Xdebug.swift in Sources */, C42337A3281F19F000459A48 /* Xdebug.swift in Sources */,
@ -1615,6 +1620,7 @@
C44C198E276E3A1C0072762D /* TerminalProgressWindowController.swift in Sources */, C44C198E276E3A1C0072762D /* TerminalProgressWindowController.swift in Sources */,
C485707828BF456300539B36 /* Warning.swift in Sources */, C485707828BF456300539B36 /* Warning.swift in Sources */,
C415938027A1B54F00D2E1B7 /* PhpFrameworks.swift in Sources */, C415938027A1B54F00D2E1B7 /* PhpFrameworks.swift in Sources */,
C40F505628ECA64E004AD45B /* Testables.swift in Sources */,
C4D9ADC9277611A0007277F4 /* InternalSwitcher.swift in Sources */, C4D9ADC9277611A0007277F4 /* InternalSwitcher.swift in Sources */,
C449B4F227EE7FC400C47E8A /* DomainListPhpCell.swift in Sources */, C449B4F227EE7FC400C47E8A /* DomainListPhpCell.swift in Sources */,
C42CFB1A27DFE8BD00862737 /* NginxConfigurationTest.swift in Sources */, C42CFB1A27DFE8BD00862737 /* NginxConfigurationTest.swift in Sources */,

View File

@ -66,6 +66,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
logger.verbosity = .info logger.verbosity = .info
#if DEBUG #if DEBUG
logger.verbosity = .performance logger.verbosity = .performance
// TODO: Enable to fake broken setup during testing
ActiveShell.useTestable(Testables.broken)
#endif #endif
if CommandLine.arguments.contains("--v") { if CommandLine.arguments.contains("--v") {
logger.verbosity = .performance logger.verbosity = .performance

View File

@ -115,7 +115,7 @@ class Startup {
// Make sure we can detect one or more PHP installations. // Make sure we can detect one or more PHP installations.
// ================================================================================= // =================================================================================
EnvironmentCheck( EnvironmentCheck(
command: { return !LegacyShell.pipe("ls \(Paths.optPath) | grep php").contains("php") }, command: { return await !Shell.pipe("ls \(Paths.optPath) | grep php").out.contains("php") },
name: "`ls \(Paths.optPath) | grep php` returned php result", name: "`ls \(Paths.optPath) | grep php` returned php result",
titleText: "startup.errors.php_opt.title".localized, titleText: "startup.errors.php_opt.title".localized,
subtitleText: "startup.errors.php_opt.subtitle".localized( subtitleText: "startup.errors.php_opt.subtitle".localized(
@ -143,14 +143,14 @@ class Startup {
// functioning correctly. Let the user know that they need to run `valet trust`. // functioning correctly. Let the user know that they need to run `valet trust`.
// ================================================================================= // =================================================================================
EnvironmentCheck( EnvironmentCheck(
command: { return !LegacyShell.pipe("cat /private/etc/sudoers.d/brew").contains(Paths.brew) }, command: { return await !Shell.pipe("cat /private/etc/sudoers.d/brew").out.contains(Paths.brew) },
name: "`/private/etc/sudoers.d/brew` contains brew", name: "`/private/etc/sudoers.d/brew` contains brew",
titleText: "startup.errors.sudoers_brew.title".localized, titleText: "startup.errors.sudoers_brew.title".localized,
subtitleText: "startup.errors.sudoers_brew.subtitle".localized, subtitleText: "startup.errors.sudoers_brew.subtitle".localized,
descriptionText: "startup.errors.sudoers_brew.desc".localized descriptionText: "startup.errors.sudoers_brew.desc".localized
), ),
EnvironmentCheck( EnvironmentCheck(
command: { return !LegacyShell.pipe("cat /private/etc/sudoers.d/valet").contains(Paths.valet) }, command: { return await !Shell.pipe("cat /private/etc/sudoers.d/valet").out.contains(Paths.valet) },
name: "`/private/etc/sudoers.d/valet` contains valet", name: "`/private/etc/sudoers.d/valet` contains valet",
titleText: "startup.errors.sudoers_valet.title".localized, titleText: "startup.errors.sudoers_valet.title".localized,
subtitleText: "startup.errors.sudoers_valet.subtitle".localized, subtitleText: "startup.errors.sudoers_valet.subtitle".localized,
@ -200,10 +200,10 @@ class Startup {
// ================================================================================= // =================================================================================
EnvironmentCheck( EnvironmentCheck(
command: { command: {
let nodePath = await Shell.pipe("which node").out
return App.architecture == "x86_64" return App.architecture == "x86_64"
&& FileManager.default.fileExists(atPath: "/usr/local/bin/which") && FileManager.default.fileExists(atPath: "/usr/local/bin/which")
&& LegacyShell.pipe("which node", requiresPath: false) && nodePath.contains("env: node: No such file or directory")
.contains("env: node: No such file or directory")
}, },
name: "`env: node` issue does not apply", name: "`env: node` issue does not apply",
titleText: "startup.errors.which_alias_issue.title".localized, titleText: "startup.errors.which_alias_issue.title".localized,
@ -215,7 +215,7 @@ class Startup {
// ================================================================================= // =================================================================================
EnvironmentCheck( EnvironmentCheck(
command: { command: {
return valet("--version", sudo: false) return await Shell.pipe("valet --version").out
.contains("Composer detected issues in your platform") .contains("Composer detected issues in your platform")
}, },
name: "`no global composer issues", name: "`no global composer issues",
@ -228,7 +228,7 @@ class Startup {
// ================================================================================= // =================================================================================
EnvironmentCheck( EnvironmentCheck(
command: { command: {
let output = valet("--version", sudo: false) let output = await Shell.pipe("valet --version").out
// Failure condition #1: does not contain Laravel Valet // Failure condition #1: does not contain Laravel Valet
if !output.contains("Laravel Valet") { if !output.contains("Laravel Valet") {
return true return true

View File

@ -62,6 +62,14 @@ struct FakeShellOutput {
struct BatchFakeShellOutput { struct BatchFakeShellOutput {
var items: [FakeShellOutput] var items: [FakeShellOutput]
static func with(_ items: [FakeShellOutput]) -> BatchFakeShellOutput {
return BatchFakeShellOutput(items: items)
}
static func instant(_ output: String, _ stream: ShellStream = .stdOut) -> BatchFakeShellOutput {
return BatchFakeShellOutput(items: [.instant(output, stream)])
}
/** /**
Outputs the fake shell output as expected. Outputs the fake shell output as expected.
*/ */

View File

@ -0,0 +1,29 @@
//
// Testables.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 04/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Foundation
// swiftlint:disable colon trailing_comma
class Testables {
typealias Configuration = [String: BatchFakeShellOutput]
// TODO: Complete broken configuration setup
static var broken: Configuration {
return [
"php -v" : .instant(""),
"ls /opt/homebrew/opt | grep php" : .instant(""),
]
}
// TODO: All expected, correct Terminal responses
static var working: Configuration {
return [:]
}
}