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

👌 Use fake filesystem

This commit is contained in:
2022-10-12 22:38:03 +02:00
parent 12a4efc775
commit ad46f51d73
4 changed files with 41 additions and 14 deletions

View File

@ -989,8 +989,8 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C4F787A728EF812600790735 /* Testables */, C4F787A728EF812600790735 /* Testables */,
C4C8900128F0E27900CE5E97 /* Filesystem */,
C4F787A628EF811000790735 /* Shell */, C4F787A628EF811000790735 /* Shell */,
C4C8900128F0E27900CE5E97 /* Filesystem */,
C40C7F2127721F7300DDDCDC /* Core */, C40C7F2127721F7300DDDCDC /* Core */,
54B20EDF263AA22C00D3250E /* PHP */, 54B20EDF263AA22C00D3250E /* PHP */,
C44CCD4327AFE93300CE40E5 /* Errors */, C44CCD4327AFE93300CE40E5 /* Errors */,

View File

@ -38,7 +38,11 @@ class TestableConfigurations {
return TestableConfiguration( return TestableConfiguration(
architecture: "arm64", architecture: "arm64",
filesystem: [ filesystem: [
"/opt/homebrew/brew" "/opt/homebrew/bin/brew"
: .fake(.binary),
"/opt/homebrew/bin/php"
: .fake(.binary),
"/opt/homebrew/bin/valet"
: .fake(.binary), : .fake(.binary),
"/opt/homebrew/opt/php" "/opt/homebrew/opt/php"
: .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1"), : .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1"),
@ -47,13 +51,15 @@ class TestableConfigurations {
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php" "/opt/homebrew/Cellar/php/8.1.10_1/bin/php"
: .fake(.binary), : .fake(.binary),
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php-config" "/opt/homebrew/Cellar/php/8.1.10_1/bin/php-config"
: .fake(.binary) : .fake(.binary),
"~/.config/valet"
: .fake(.directory)
], ],
shellOutput: [ shellOutput: [
"sysctl -n sysctl.proc_translated" "sysctl -n sysctl.proc_translated"
: .instant("0"), : .instant("0"),
"id -un" "id -un"
: .instant("nicoverbruggen"), : .instant("user"),
"which node" "which node"
: .instant("/opt/homebrew/bin/node"), : .instant("/opt/homebrew/bin/node"),
"php -v" "php -v"

View File

@ -16,28 +16,39 @@ class TestableFileSystem: FileSystemProtocol {
var files: [String: FakeFile] var files: [String: FakeFile]
func isExecutableFile(_ path: String) -> Bool { func isExecutableFile(_ path: String) -> Bool {
// TODO guard let file = files[path] else {
return false return false
}
return file.type == .binary
} }
func exists(_ path: String) -> Bool { func exists(_ path: String) -> Bool {
// TODO return files.keys.contains(path)
return false
} }
func fileExists(_ path: String) -> Bool { func fileExists(_ path: String) -> Bool {
// TODO guard let file = files[path] else {
return false return false
}
return [.binary, .symlink, .text].contains(file.type)
} }
func directoryExists(_ path: String) -> Bool { func directoryExists(_ path: String) -> Bool {
// TODO guard let file = files[path] else {
return false return false
}
return [.directory].contains(file.type)
} }
func fileIsSymlink(_ path: String) -> Bool { func fileIsSymlink(_ path: String) -> Bool {
// TODO guard let file = files[path] else {
return false return false
}
return file.type == .symlink
} }
} }

View File

@ -31,7 +31,17 @@ class App {
return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
} }
/**
A fake architecture.
When set, the real machine's system architecture is not used,
but this fixed value is used instead.
*/
static var fakeArchitecture: String?
/** The system architecture. Paths differ based on this value. */
static var architecture: String { static var architecture: String {
if fakeArchitecture != nil { return fakeArchitecture! }
var systeminfo = utsname() var systeminfo = utsname()
uname(&systeminfo) uname(&systeminfo)
let machine = withUnsafeBytes(of: &systeminfo.machine) {bufPtr->String in let machine = withUnsafeBytes(of: &systeminfo.machine) {bufPtr->String in