From e20d3ffd22ba2388d8f5949219986e93af6fef71 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 3 Jan 2023 19:29:44 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20WIP:=20Various=20fixes?= =?UTF-8?q?=20and=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed `brewPhpAlias` (must be configurable later) - Added TODOs for where the filesystem abstraction is required - Set `Homebrew.fake` early on when applying testable configuration - Evaluate `FakeValetSite` compatibility again - Never display sponsor alert when running tests - Upgrade TestableConfiguration.working to use PHP 8.2 --- PHP Monitor.xcodeproj/project.pbxproj | 8 ---- phpmon/Common/PHP/PHP Version/PhpEnv.swift | 2 + phpmon/Common/PHP/PhpConfigurationFile.swift | 1 + .../Testables/TestableConfiguration.swift | 15 +++++++- .../Valet/Sites/FakeValetSite.swift | 11 +----- phpmon/Domain/Preferences/Stats.swift | 4 ++ phpmon/Domain/SwiftUI/Menu/ServicesView.swift | 6 ++- tests/Shared/TestableConfigurations.swift | 38 ++++++++++--------- 8 files changed, 47 insertions(+), 38 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index a948178..d8a78e6 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -1320,7 +1320,6 @@ C471E6D928F9AFC20021E251 /* Testables */ = { isa = PBXGroup; children = ( - C471E6DB28F9AFD10021E251 /* Command */, C471E6DA28F9AFCB0021E251 /* Filesystem */, C413E43328DA3E8F00AE33C7 /* Shell */, C4E2E84628FC1D8C003B070C /* TestableConfigurationTest.swift */, @@ -1337,13 +1336,6 @@ path = Filesystem; sourceTree = ""; }; - C471E6DB28F9AFD10021E251 /* Command */ = { - isa = PBXGroup; - children = ( - ); - path = Command; - sourceTree = ""; - }; C471E79628F9B4260021E251 /* tests */ = { isa = PBXGroup; children = ( diff --git a/phpmon/Common/PHP/PHP Version/PhpEnv.swift b/phpmon/Common/PHP/PHP Version/PhpEnv.swift index 9d83559..bba11ac 100644 --- a/phpmon/Common/PHP/PHP Version/PhpEnv.swift +++ b/phpmon/Common/PHP/PHP Version/PhpEnv.swift @@ -57,6 +57,8 @@ class PhpEnv { As such, we take that information from Homebrew. */ static var brewPhpAlias: String { + if Homebrew.fake { return "8.2" } + return Self.shared.homebrewPackage.version } diff --git a/phpmon/Common/PHP/PhpConfigurationFile.swift b/phpmon/Common/PHP/PhpConfigurationFile.swift index a0d4191..f88869d 100644 --- a/phpmon/Common/PHP/PhpConfigurationFile.swift +++ b/phpmon/Common/PHP/PhpConfigurationFile.swift @@ -35,6 +35,7 @@ class PhpConfigurationFile: CreatedFromFile { let path = filePath.replacingOccurrences(of: "~", with: Paths.homePath) do { + // TODO: Use FileSystem abstraction let fileContents = try String(contentsOfFile: path) return Self.init(path: path, contents: fileContents) } catch { diff --git a/phpmon/Common/Testables/TestableConfiguration.swift b/phpmon/Common/Testables/TestableConfiguration.swift index beaf040..f3b69c3 100644 --- a/phpmon/Common/Testables/TestableConfiguration.swift +++ b/phpmon/Common/Testables/TestableConfiguration.swift @@ -17,6 +17,7 @@ public struct TestableConfiguration: Codable { func apply() { Log.separator() Log.info("USING TESTABLE CONFIGURATION...") + Homebrew.fake = true Log.separator() Log.info("Applying fake shell...") ActiveShell.useTestable(shellOutput) @@ -27,7 +28,6 @@ public struct TestableConfiguration: Codable { Log.info("Applying fake scanner...") ValetScanner.useFake() Log.info("Applying fake services manager...") - Homebrew.fake = true ServicesManager.useFake() Log.info("Applying fake Valet domain interactor...") ValetInteractor.useFake() @@ -46,6 +46,19 @@ public struct TestableConfiguration: Codable { static func loadFrom(path: String) -> TestableConfiguration { let url = URL(fileURLWithPath: path.replacingTildeWithHomeDirectory) + if !FileManager.default.fileExists(atPath: url.path) { + /* + You will need to run the `TestableConfigurationTest` test, + which will generate two configuration files you can use. + */ + fatalError("Error: the expected configuration file at \(url.path) is missing!") + } + + /* + If the decoder below fails to decode the configuration file, + the configuration may have been updated. + In that case, you will need to run the test (see above) again. + */ return try! JSONDecoder().decode( TestableConfiguration.self, from: try! String(contentsOf: url, encoding: .utf8).data(using: .utf8)! diff --git a/phpmon/Domain/Integrations/Valet/Sites/FakeValetSite.swift b/phpmon/Domain/Integrations/Valet/Sites/FakeValetSite.swift index 5fc8074..e462f46 100644 --- a/phpmon/Domain/Integrations/Valet/Sites/FakeValetSite.swift +++ b/phpmon/Domain/Integrations/Valet/Sites/FakeValetSite.swift @@ -35,15 +35,6 @@ class FakeValetSite: ValetSite { self.isolatedPhpVersion = PhpInstallation(isolated) } - // TODO: Resolve this at a later time - /* - self.composerPhpCompatibleWithLinked = self.composerPhp.split(separator: "|") - .map { string in - let origin = self.isolatedPhpVersion?.versionNumber.short ?? PhpEnv.phpInstall.version.long - return !PhpVersionNumberCollection.make(from: [origin]) - .matching(constraint: string.trimmingCharacters(in: .whitespacesAndNewlines)) - .isEmpty - }.contains(true) - */ + self.evaluateCompatibility() } } diff --git a/phpmon/Domain/Preferences/Stats.swift b/phpmon/Domain/Preferences/Stats.swift index 229da9f..ab25b9b 100644 --- a/phpmon/Domain/Preferences/Stats.swift +++ b/phpmon/Domain/Preferences/Stats.swift @@ -87,6 +87,10 @@ class Stats { */ public static func evaluateSponsorMessageShouldBeDisplayed() { + if Homebrew.fake { + return Log.info("A fake environment is in use, skipping sponsor alert.") + } + if Bundle.main.bundleIdentifier?.contains("beta") ?? false { return Log.info("Sponsor messages never apply to beta builds.") } diff --git a/phpmon/Domain/SwiftUI/Menu/ServicesView.swift b/phpmon/Domain/SwiftUI/Menu/ServicesView.swift index ade3da5..9710955 100644 --- a/phpmon/Domain/SwiftUI/Menu/ServicesView.swift +++ b/phpmon/Domain/SwiftUI/Menu/ServicesView.swift @@ -156,7 +156,11 @@ struct ServicesView_Previews: PreviewProvider { .previewDisplayName("Loading") ServicesView(manager: FakeServicesManager( - formulae: ["php", "nginx", "dnsmasq", "thing1", "thing2", "thing3", "thing4", "thing5", "thing6", "thing7", "thing8"], + formulae: [ + "php", "nginx", "dnsmasq", "thing1", + "thing2", "thing3", "thing4", "thing5", + "thing6", "thing7", "thing8" + ], status: .active ), perRow: 4) .frame(width: 330.0) diff --git a/tests/Shared/TestableConfigurations.swift b/tests/Shared/TestableConfigurations.swift index 49547f6..90f6ed0 100644 --- a/tests/Shared/TestableConfigurations.swift +++ b/tests/Shared/TestableConfigurations.swift @@ -25,14 +25,14 @@ class TestableConfigurations { "/opt/homebrew/bin/valet" : .fake(.binary), "/opt/homebrew/opt/php" - : .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1"), - "/opt/homebrew/opt/php@8.1/bin/php" - : .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1/bin/php"), - "/opt/homebrew/Cellar/php/8.1.10_1/bin/php" + : .fake(.symlink, "/opt/homebrew/Cellar/php/8.2.0"), + "/opt/homebrew/opt/php@8.2/bin/php" + : .fake(.symlink, "/opt/homebrew/Cellar/php/8.2.0/bin/php"), + "/opt/homebrew/Cellar/php/8.2.0/bin/php" : .fake(.binary), - "/opt/homebrew/Cellar/php/8.1.10_1/bin/php-config" + "/opt/homebrew/Cellar/php/8.2.0/bin/php-config" : .fake(.binary), - "/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf" + "/opt/homebrew/etc/php/8.2/php-fpm.d/www.conf" : .fake(.text), "~/.config/valet/config.json" : .fake(.text, """ @@ -45,7 +45,7 @@ class TestableConfigurations { "loopback": "127.0.0.1" } """), - "/opt/homebrew/etc/php/8.1/php-fpm.d/valet-fpm.conf" + "/opt/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf" : .fake(.text), ], shellOutput: [ @@ -57,15 +57,15 @@ class TestableConfigurations { : .instant("/opt/homebrew/bin/node"), "php -v" : .instant(""" - PHP 8.1.10 (cli) (built: Sep 3 2022 12:09:27) (NTS) + PHP 8.2.0 (cli) (built: Dec XX 20XX XX:XX:XX) (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 + Zend Engine vX.X, Copyright (c) Zend Technologies + with Zend OPcache vX.X, Copyright (c), by Zend Technologies """), "ls /opt/homebrew/opt | grep php" : .instant("php"), "ls /opt/homebrew/opt | grep php@" - : .instant("php@8.1"), + : .instant("php@8.2"), "sudo /opt/homebrew/bin/brew services info dnsmasq --json" : .delayed(0.2, """ [ @@ -110,7 +110,7 @@ class TestableConfigurations { nicoverbruggen/cask shivammathur/php """), - "chmod +x /Users/nicoverbruggen/.config/phpmon/bin/pm81" + "chmod +x /Users/nicoverbruggen/.config/phpmon/bin/pm82" : .instant(""), "mkdir -p ~/.config/phpmon" : .instant(""), @@ -138,6 +138,8 @@ class TestableConfigurations { : .instant("version '5.6.2_976'"), "/opt/homebrew/bin/brew unlink php" : .delayed(0.2, "OK"), + "/opt/homebrew/bin/brew unlink php@8.2" + : .delayed(0.2, "OK"), "/opt/homebrew/bin/brew link php --overwrite --force" : .delayed(0.2, "OK"), "sudo /opt/homebrew/bin/brew services stop php" @@ -152,20 +154,20 @@ class TestableConfigurations { : .delayed(0.2, "OK"), "sudo /opt/homebrew/bin/brew services start dnsmasq" : .delayed(0.2, "OK"), - "ln -sF ~/.config/valet/valet81.sock ~/.config/valet/valet.sock" + "ln -sF ~/.config/valet/valet82.sock ~/.config/valet/valet.sock" : .instant("OK"), ], commandOutput: [ - "/opt/homebrew/bin/php-config --version": "8.1.10", + "/opt/homebrew/bin/php-config --version": "8.2.0", "/opt/homebrew/bin/php -r echo ini_get('memory_limit');": "512M", "/opt/homebrew/bin/php -r echo ini_get('upload_max_filesize');": "512M", "/opt/homebrew/bin/php -r echo ini_get('post_max_size');": "512M", "/opt/homebrew/bin/php -r echo php_ini_scanned_files();" : """ - /opt/homebrew/etc/php/8.1/conf.d/error_log.ini, - /opt/homebrew/etc/php/8.1/conf.d/ext-opcache.ini, - /opt/homebrew/etc/php/8.1/conf.d/php-memory-limits.ini, - /opt/homebrew/etc/php/8.1/conf.d/xdebug.ini + /opt/homebrew/etc/php/8.2/conf.d/error_log.ini, + /opt/homebrew/etc/php/8.2/conf.d/ext-opcache.ini, + /opt/homebrew/etc/php/8.2/conf.d/php-memory-limits.ini, + /opt/homebrew/etc/php/8.2/conf.d/xdebug.ini """ ] )