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

🏗 Testable terminal output

This commit is contained in:
2022-10-04 23:42:43 +02:00
parent 0b33116eb0
commit 1fd7db15a7
6 changed files with 129 additions and 15 deletions

View File

@ -211,6 +211,8 @@
C4A81CA528C67101008DD9D1 /* PMTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A81CA328C67101008DD9D1 /* PMTableView.swift */; };
C4AC51FC27E27F47008528CA /* DomainListKindCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AC51FB27E27F47008528CA /* DomainListKindCell.swift */; };
C4ACA38F25C754C100060C66 /* PhpExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4ACA38E25C754C100060C66 /* PhpExtension.swift */; };
C4AD38B228ECD9D300FA8D83 /* TestableFilesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AD38B128ECD9D300FA8D83 /* TestableFilesystem.swift */; };
C4AD38B328ECD9D300FA8D83 /* TestableFilesystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AD38B128ECD9D300FA8D83 /* TestableFilesystem.swift */; };
C4AF9F72275445FF00D44ED0 /* valet-config.json in Resources */ = {isa = PBXBuildFile; fileRef = C4AF9F70275445FF00D44ED0 /* valet-config.json */; };
C4AF9F78275447F100D44ED0 /* ValetConfigurationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AF9F76275447F100D44ED0 /* ValetConfigurationTest.swift */; };
C4AF9F7A2754499000D44ED0 /* Valet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4AF9F792754499000D44ED0 /* Valet.swift */; };
@ -459,6 +461,7 @@
C4A81CA328C67101008DD9D1 /* PMTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PMTableView.swift; sourceTree = "<group>"; };
C4AC51FB27E27F47008528CA /* DomainListKindCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DomainListKindCell.swift; sourceTree = "<group>"; };
C4ACA38E25C754C100060C66 /* PhpExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhpExtension.swift; sourceTree = "<group>"; };
C4AD38B128ECD9D300FA8D83 /* TestableFilesystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestableFilesystem.swift; sourceTree = "<group>"; };
C4AF9F70275445FF00D44ED0 /* valet-config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "valet-config.json"; sourceTree = "<group>"; };
C4AF9F76275447F100D44ED0 /* ValetConfigurationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValetConfigurationTest.swift; sourceTree = "<group>"; };
C4AF9F792754499000D44ED0 /* Valet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Valet.swift; sourceTree = "<group>"; };
@ -887,6 +890,7 @@
C46EBC4928DB966A007ACC74 /* TestableShell.swift */,
C46EBC4328DB95F0007ACC74 /* Shellable.swift */,
C40F505428ECA64E004AD45B /* Testables.swift */,
C4AD38B128ECD9D300FA8D83 /* TestableFilesystem.swift */,
);
path = Next;
sourceTree = "<group>";
@ -1400,6 +1404,7 @@
C44264BE2850B86C007400F1 /* SwiftUIHelper.swift in Sources */,
C4E9D2C02878B336008FFDAD /* OnboardingView.swift in Sources */,
C4F2E4372752F0870020E974 /* HomebrewDiagnostics.swift in Sources */,
C4AD38B228ECD9D300FA8D83 /* TestableFilesystem.swift in Sources */,
C4EB53E528551F9B006F9937 /* HeaderView.swift in Sources */,
C40FE737282ABA4F00A302C2 /* AppVersion.swift in Sources */,
C44A874828905BB000498BC4 /* ProgressVC.swift in Sources */,
@ -1588,6 +1593,7 @@
C41E871B2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */,
C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */,
C4068CAB27B0890D00544CD5 /* MenuBarIcons.swift in Sources */,
C4AD38B328ECD9D300FA8D83 /* TestableFilesystem.swift in Sources */,
C40C5C9D2846A40600E28255 /* Preset.swift in Sources */,
C4F30B09278E1A0E00755FCE /* CustomPrefs.swift in Sources */,
C40FE738282ABA4F00A302C2 /* AppVersion.swift in Sources */,

View File

@ -121,6 +121,8 @@ public class LegacyShell {
public func createTask(for command: String, requiresPath: Bool) -> Process {
var completeCommand = ""
Log.info("LEGACY COMMAND: \(command)")
if requiresPath {
// Basic export (PATH)
completeCommand += "export PATH=\(Paths.binPath):$PATH && "

View File

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

View File

@ -0,0 +1,24 @@
//
// TestableFilesystem.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 04/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import Foundation
class TestableFilesystem {}
enum FakeFileType {
case binary, text, directory, symlink
}
struct FakeFile {
var type: FakeFileType
var content: String?
public static func fake(_ type: FakeFileType, _ content: String? = nil) -> FakeFile {
return FakeFile(type: type, content: content)
}
}

View File

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

View File

@ -8,22 +8,94 @@
import Foundation
//
struct TestableConfiguration {
let architecture: String
let filesystem: [String: FakeFile]
let shellOutput: [String: BatchFakeShellOutput]
}
// 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(""),
]
static var broken: TestableConfiguration {
return TestableConfiguration(
architecture: "arm64",
filesystem: [:],
shellOutput: [
"id -un" : .instant("username"),
"php -v" : .instant(""),
"ls /opt/homebrew/opt | grep php" : .instant(""),
]
)
}
// TODO: All expected, correct Terminal responses
static var working: Configuration {
return [:]
static var working: TestableConfiguration {
return TestableConfiguration(
architecture: "arm64",
filesystem: [
"/opt/homebrew/brew"
: .fake(.binary),
"/opt/homebrew/opt/php"
: .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1"),
"/opt/homebrew/Cellar/php/8.1.10_1"
: .fake(.directory),
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php"
: .fake(.binary),
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php-config"
: .fake(.binary)
],
shellOutput: [
"id -un"
: .instant("username"),
"which node"
: .instant("/opt/homebrew/bin/node"),
"php -v"
: .instant("""
PHP 8.1.10 (cli) (built: Sep 3 2022 12:09:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies
"""),
"ls /opt/homebrew/opt | grep php"
: .instant("php"),
"sudo /opt/homebrew/bin/brew services info nginx --json"
: .delayed(0.2, """
[
{
"name": "nginx",
"service_name": "homebrew.mxcl.nginx",
"running": true,
"loaded": true,
"schedulable": false,
"pid": 133,
"exit_code": 0,
"user": "root",
"status": "started",
"file": "/Library/LaunchDaemons/homebrew.mxcl.nginx.plist",
"command": "/opt/homebrew/opt/nginx/bin/nginx -g daemon off;",
"working_dir": "/opt/homebrew",
"root_dir": null,
"log_path": null,
"error_log_path": null,
"interval": null,
"cron": null
}
]
"""),
"cat /private/etc/sudoers.d/brew"
: .instant("""
Cmnd_Alias BREW = /opt/homebrew/bin/brew *
%admin ALL=(root) NOPASSWD:SETENV: BREW
"""),
"cat /private/etc/sudoers.d/valet"
: .instant("""
Cmnd_Alias VALET = /opt/homebrew/bin/valet *
%admin ALL=(root) NOPASSWD:SETENV: VALET
"""),
"valet --version"
: .instant("Laravel Valet 3.1.11")
]
)
}
}