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;
children = (
C4F787A728EF812600790735 /* Testables */,
C4C8900128F0E27900CE5E97 /* Filesystem */,
C4F787A628EF811000790735 /* Shell */,
C4C8900128F0E27900CE5E97 /* Filesystem */,
C40C7F2127721F7300DDDCDC /* Core */,
54B20EDF263AA22C00D3250E /* PHP */,
C44CCD4327AFE93300CE40E5 /* Errors */,

View File

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

View File

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

View File

@ -31,7 +31,17 @@ class App {
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 {
if fakeArchitecture != nil { return fakeArchitecture! }
var systeminfo = utsname()
uname(&systeminfo)
let machine = withUnsafeBytes(of: &systeminfo.machine) {bufPtr->String in