1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-07 05:10:06 +01:00

Add testable configuration for Valet-free env

This commit is contained in:
2023-01-17 19:16:36 +01:00
parent c6f2167c92
commit 89642de12e
8 changed files with 181 additions and 28 deletions

View File

@@ -97,13 +97,13 @@ class PhpEnv {
let supportedByValet: Set<String> = {
guard let version = Valet.shared.version else {
return []
return Constants.DetectedPhpVersions
}
return Constants.ValetSupportedPhpVersionMatrix[version.major] ?? []
}()
var supportedVersions = versions.intersection(supportedByValet)
var supportedVersions = Valet.installed ? versions.intersection(supportedByValet) : versions
// Make sure the aliased version is detected
// The user may have `php` installed, but not e.g. `php@8.0`

View File

@@ -24,12 +24,15 @@ public struct TestableConfiguration: Codable {
ActiveFileSystem.useTestable(filesystem)
Log.info("Applying fake commands...")
ActiveCommand.useTestable(commandOutput)
Log.info("Applying fake scanner...")
ValetScanner.useFake()
Log.info("Applying fake services manager...")
ServicesManager.useFake()
Log.info("Applying fake Valet domain interactor...")
ValetInteractor.useFake()
if Valet.shared.installed {
Log.info("Applying fake scanner...")
ValetScanner.useFake()
Log.info("Applying fake services manager...")
ServicesManager.useFake()
Log.info("Applying fake Valet domain interactor...")
ValetInteractor.useFake()
}
}
func toJson(pretty: Bool = false) -> String {

View File

@@ -9,24 +9,10 @@
import Foundation
public class EnvironmentManager {
var values: [EnvironmentProperty: Bool] = [:]
static var values: [EnvironmentProperty: Bool] = [:]
public func process() async {
self.values[.hasValetInstalled] = await !{
let output = await Shell.pipe("valet --version").out
// Failure condition #1: does not contain Laravel Valet
if !output.contains("Laravel Valet") {
return true
}
// Extract the version number
Valet.shared.version = try! VersionNumber.parse(VersionExtractor.from(output)!)
// Get the actual version
return Valet.shared.version == nil
}() // returns true if none of the failure conditions are met
Self.values[.hasValetInstalled] = Valet.shared.installed
}
}

View File

@@ -136,7 +136,7 @@ class Startup {
descriptionText: "startup.errors.php_opt.desc".localized
),
]),
EnvironmentCheckGroup(name: "valet", condition: { return Valet.installed() }, checks: [
EnvironmentCheckGroup(name: "valet", condition: { return Valet.shared.installed }, checks: [
// =================================================================================
// The Valet binary must exist.
// =================================================================================

View File

@@ -57,10 +57,17 @@ class Valet {
}
}
public static func installed() -> Bool {
return FileSystem.fileExists(Paths.binPath.appending("/valet"))
static var installed: Bool {
return self.shared.installed
}
lazy var installed: Bool = {
return false
// TODO: Make this lazy
// return FileSystem.fileExists(Paths.binPath.appending("/valet"))
}()
/**
Check if a particular feature is enabled.
*/
@@ -79,6 +86,10 @@ class Valet {
Notify the user about a non-default TLD being set.
*/
public static func notifyAboutUnsupportedTLD() {
if !Valet.shared.installed {
return
}
if Valet.shared.config.tld != "test" && Preferences.isEnabled(.warnAboutNonStandardTLD) {
Task { @MainActor in
BetterAlert().withInformation(
@@ -121,7 +132,9 @@ class Valet {
handle all PHP versions including isolation, it needs to know about all sites.
*/
public func startPreloadingSites() async {
await self.reloadSites()
if Valet.shared.installed {
await self.reloadSites()
}
}
/**