From 412b7bad5cc8147d01973aba789ffcefe9ef3e3a Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 6 Feb 2023 19:09:14 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20Fix=20generated=20script=20(?= =?UTF-8?q?#231)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Common/Core/Actions.swift | 19 ++++++++++--------- phpmon/Common/Core/Homebrew.swift | 6 +++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/phpmon/Common/Core/Actions.swift b/phpmon/Common/Core/Actions.swift index 86408df..8abc354 100644 --- a/phpmon/Common/Core/Actions.swift +++ b/phpmon/Common/Core/Actions.swift @@ -13,21 +13,21 @@ class Actions { // MARK: - Services public static func restartPhpFpm() async { - await brew("services restart \(Homebrew.Formulae.php.name)", sudo: Homebrew.Formulae.php.elevated) + await brew("services restart \(Homebrew.Formulae.php)", sudo: Homebrew.Formulae.php.elevated) } public static func restartNginx() async { - await brew("services restart \(Homebrew.Formulae.nginx.name)", sudo: Homebrew.Formulae.nginx.elevated) + await brew("services restart \(Homebrew.Formulae.nginx)", sudo: Homebrew.Formulae.nginx.elevated) } public static func restartDnsMasq() async { - await brew("services restart \(Homebrew.Formulae.dnsmasq.name)", sudo: Homebrew.Formulae.dnsmasq.elevated) + await brew("services restart \(Homebrew.Formulae.dnsmasq)", sudo: Homebrew.Formulae.dnsmasq.elevated) } public static func stopValetServices() async { - await brew("services stop \(Homebrew.Formulae.php.name)", sudo: Homebrew.Formulae.php.elevated) - await brew("services stop \(Homebrew.Formulae.nginx.name)", sudo: Homebrew.Formulae.nginx.elevated) - await brew("services stop \(Homebrew.Formulae.dnsmasq.name)", sudo: Homebrew.Formulae.dnsmasq.elevated) + await brew("services stop \(Homebrew.Formulae.php)", sudo: Homebrew.Formulae.php.elevated) + await brew("services stop \(Homebrew.Formulae.nginx)", sudo: Homebrew.Formulae.nginx.elevated) + await brew("services stop \(Homebrew.Formulae.dnsmasq)", sudo: Homebrew.Formulae.dnsmasq.elevated) } public static func fixHomebrewPermissions() throws { @@ -54,9 +54,10 @@ class Actions { + " && " + cellarCommands.joined(separator: " && ") - let appleScript = NSAppleScript( - source: "do shell script \"\(script)\" with administrator privileges" - ) + let source = "do shell script \"\(script)\" with administrator privileges" + + Log.perf(source) + let appleScript = NSAppleScript(source: source) let eventResult: NSAppleEventDescriptor? = appleScript?.executeAndReturnError(nil) diff --git a/phpmon/Common/Core/Homebrew.swift b/phpmon/Common/Core/Homebrew.swift index c570f2a..de96a64 100644 --- a/phpmon/Common/Core/Homebrew.swift +++ b/phpmon/Common/Core/Homebrew.swift @@ -36,10 +36,14 @@ class Homebrew { } } -class HomebrewFormula: Equatable, Hashable { +class HomebrewFormula: Equatable, Hashable, CustomStringConvertible { let name: String let elevated: Bool + var description: String { + return name + } + init(_ name: String, elevated: Bool = true) { self.name = name self.elevated = elevated From 9fceab3e2e767bd4ff261a2e9242c371e25b6264 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 13 Feb 2023 17:30:01 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9B=20Adjusted=20for=20new=20Homeb?= =?UTF-8?q?rew=20JSON=20output=20(#235)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/PHP/Homebrew/HomebrewPackage.swift | 2 - phpmon/Domain/App/EnvironmentManager.swift | 3 +- tests/unit/Parsers/HomebrewPackageTest.swift | 5 +- tests/unit/Test Files/brew/brew-formula.json | 143 ++++++++++-------- 4 files changed, 85 insertions(+), 68 deletions(-) diff --git a/phpmon/Common/PHP/Homebrew/HomebrewPackage.swift b/phpmon/Common/PHP/Homebrew/HomebrewPackage.swift index 100a6a3..b250c80 100644 --- a/phpmon/Common/PHP/Homebrew/HomebrewPackage.swift +++ b/phpmon/Common/PHP/Homebrew/HomebrewPackage.swift @@ -8,8 +8,6 @@ import Foundation struct HomebrewPackage: Decodable { - - let name: String let full_name: String let aliases: [String] let installed: [HomebrewInstalled] diff --git a/phpmon/Domain/App/EnvironmentManager.swift b/phpmon/Domain/App/EnvironmentManager.swift index 9275084..fa527d6 100644 --- a/phpmon/Domain/App/EnvironmentManager.swift +++ b/phpmon/Domain/App/EnvironmentManager.swift @@ -17,7 +17,7 @@ public class EnvironmentManager { // Failure condition #1: does not contain Laravel Valet if !output.contains("Laravel Valet") { - return true + return false } // Extract the version number @@ -25,7 +25,6 @@ public class EnvironmentManager { // Get the actual version return Valet.shared.version == nil - }() // returns true if none of the failure conditions are met } } diff --git a/tests/unit/Parsers/HomebrewPackageTest.swift b/tests/unit/Parsers/HomebrewPackageTest.swift index a622070..a8a8916 100644 --- a/tests/unit/Parsers/HomebrewPackageTest.swift +++ b/tests/unit/Parsers/HomebrewPackageTest.swift @@ -23,11 +23,10 @@ class HomebrewPackageTest: XCTestCase { [HomebrewPackage].self, from: json.data(using: .utf8)! ).first! - XCTAssertEqual(package.name, "php") XCTAssertEqual(package.full_name, "php") - XCTAssertEqual(package.aliases.first!, "php@8.1") + XCTAssertEqual(package.aliases.first!, "php@8.2") XCTAssertEqual(package.installed.contains(where: { installed in - installed.version.starts(with: "8.1") + installed.version.starts(with: "8.2") }), true) } diff --git a/tests/unit/Test Files/brew/brew-formula.json b/tests/unit/Test Files/brew/brew-formula.json index 1029156..895492a 100644 --- a/tests/unit/Test Files/brew/brew-formula.json +++ b/tests/unit/Test Files/brew/brew-formula.json @@ -1,69 +1,77 @@ [ { - "name": "php", "full_name": "php", "tap": "homebrew/core", "oldname": null, "aliases": [ - "php@8.1" + "php@8.2" ], "versioned_formulae": [ + "php@8.1", "php@8.0", - "php@7.4", - "php@7.3", - "php@7.2" + "php@7.4" ], "desc": "General-purpose scripting language", "license": "PHP-3.01", "homepage": "https://www.php.net/", "versions": { - "stable": "8.1.10", + "stable": "8.2.2", "head": "HEAD", "bottle": true }, "urls": { "stable": { - "url": "https://www.php.net/distributions/php-8.1.10.tar.xz", + "url": "https://www.php.net/distributions/php-8.2.2.tar.xz", "tag": null, - "revision": null + "revision": null, + "checksum": "bdc4aa38e652bac86039601840bae01c0c3653972eaa6f9f93d5f71953a7ee33" + }, + "head": { + "url": "https://github.com/php/php-src.git", + "branch": "master" } }, - "revision": 1, + "revision": 0, "version_scheme": 0, "bottle": { "stable": { "rebuild": 0, "root_url": "https://ghcr.io/v2/homebrew/core", "files": { + "arm64_ventura": { + "cellar": "/opt/homebrew/Cellar", + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:ad2e6a6f1cdc65c22b39bd607cbb7305958951cf58ee87d5060717be5a8b5a45", + "sha256": "ad2e6a6f1cdc65c22b39bd607cbb7305958951cf58ee87d5060717be5a8b5a45" + }, "arm64_monterey": { "cellar": "/opt/homebrew/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:dcee33c9f445db3026a7e867805eb8f6d82e9e5599599b8c6cd8645475f7961c", - "sha256": "dcee33c9f445db3026a7e867805eb8f6d82e9e5599599b8c6cd8645475f7961c" + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:27069c973e63f38a3cb4fad1c7a2e17853bcffe318c8a957ff96a1026dff0cac", + "sha256": "27069c973e63f38a3cb4fad1c7a2e17853bcffe318c8a957ff96a1026dff0cac" }, "arm64_big_sur": { "cellar": "/opt/homebrew/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:e0590064cd32f2baa4102fa49c80056f3886a0a89aec0589d0134ecbf0e7923e", - "sha256": "e0590064cd32f2baa4102fa49c80056f3886a0a89aec0589d0134ecbf0e7923e" + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:ceef280bcd57e5f794ae59cc75e83d407c9704aa3d238b282bda52cbc644d0dd", + "sha256": "ceef280bcd57e5f794ae59cc75e83d407c9704aa3d238b282bda52cbc644d0dd" + }, + "ventura": { + "cellar": "/usr/local/Cellar", + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:22f733b7b0b0ed95cd6b0a1534b9eca4cf63fe54647394c3f7e7ac019eb019ff", + "sha256": "22f733b7b0b0ed95cd6b0a1534b9eca4cf63fe54647394c3f7e7ac019eb019ff" }, "monterey": { "cellar": "/usr/local/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:62481320613b19c6ff310bf6ed50c7d2a2253cdbf403af12ec97bccd8a97a84c", - "sha256": "62481320613b19c6ff310bf6ed50c7d2a2253cdbf403af12ec97bccd8a97a84c" + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:9ff8f5e1df5e849567cdb2ddea6d3c2a2b9cae024842c9ac65b35a01657bfc37", + "sha256": "9ff8f5e1df5e849567cdb2ddea6d3c2a2b9cae024842c9ac65b35a01657bfc37" }, "big_sur": { "cellar": "/usr/local/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:b34d96f7aad3c580a7cbdaadb8054fb9b6872111a5eec8e1bcb4a529970c8e03", - "sha256": "b34d96f7aad3c580a7cbdaadb8054fb9b6872111a5eec8e1bcb4a529970c8e03" - }, - "catalina": { - "cellar": "/usr/local/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:cc0b85dcfdd60e1d8d7fa74c9f53be5d249d068835dbc7a81edacb7a076b6c76", - "sha256": "cc0b85dcfdd60e1d8d7fa74c9f53be5d249d068835dbc7a81edacb7a076b6c76" + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:11fd1ea6da8ef728b7cacd4da8a51ed125069595abf4e37ae1552d418560c5fb", + "sha256": "11fd1ea6da8ef728b7cacd4da8a51ed125069595abf4e37ae1552d418560c5fb" }, "x86_64_linux": { "cellar": "/home/linuxbrew/.linuxbrew/Cellar", - "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:b934a5a4ad2d29b629f83962b57f638a654801d1ba21ba659a42da2e5afe3fae", - "sha256": "b934a5a4ad2d29b629f83962b57f638a654801d1ba21ba659a42da2e5afe3fae" + "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:baaa41e60f9e8125fe8f549d4813a8476a8947a1f10d7817a2ee36d8baa625f3", + "sha256": "baaa41e60f9e8125fe8f549d4813a8476a8947a1f10d7817a2ee36d8baa625f3" } } } @@ -127,34 +135,35 @@ "conflicts_with": [ ], - "caveats": "To enable PHP in Apache add the following to httpd.conf and restart Apache:\n LoadModule php_module $(brew --prefix)/opt/php/lib/httpd/modules/libphp.so\n\n \n SetHandler application/x-httpd-php\n \n\nFinally, check DirectoryIndex includes index.php\n DirectoryIndex index.php index.html\n\nThe php.ini and php-fpm.ini file can be found in:\n $(brew --prefix)/etc/php/8.1/\n", + "caveats": "To enable PHP in Apache add the following to httpd.conf and restart Apache:\n LoadModule php_module $(brew --prefix)/opt/php/lib/httpd/modules/libphp.so\n\n \n SetHandler application/x-httpd-php\n \n\nFinally, check DirectoryIndex includes index.php\n DirectoryIndex index.php index.html\n\nThe php.ini and php-fpm.ini file can be found in:\n $(brew --prefix)/etc/php/8.2/\n", "installed": [ { - "version": "8.1.10_1", + "version": "8.2.2", "used_options": [ ], "built_as_bottle": true, "poured_from_bottle": true, + "time": 1675654665, "runtime_dependencies": [ { "full_name": "apr", - "version": "1.7.0", + "version": "1.7.2", "declared_directly": true }, { "full_name": "ca-certificates", - "version": "2022-07-19", + "version": "2023-01-10", "declared_directly": false }, { "full_name": "openssl@1.1", - "version": "1.1.1q", + "version": "1.1.1s", "declared_directly": true }, { "full_name": "apr-util", - "version": "1.6.1", + "version": "1.6.3", "declared_directly": true }, { @@ -182,24 +191,24 @@ "version": "1.0.9", "declared_directly": false }, - { - "full_name": "gettext", - "version": "0.21", - "declared_directly": true - }, { "full_name": "libunistring", - "version": "1.0", + "version": "1.1", "declared_directly": false }, + { + "full_name": "gettext", + "version": "0.21.1", + "declared_directly": true + }, { "full_name": "libidn2", - "version": "2.3.3", + "version": "2.3.4", "declared_directly": false }, { "full_name": "libnghttp2", - "version": "1.49.0", + "version": "1.51.0", "declared_directly": false }, { @@ -224,7 +233,7 @@ }, { "full_name": "xz", - "version": "5.2.6", + "version": "5.4.1", "declared_directly": false }, { @@ -234,7 +243,7 @@ }, { "full_name": "curl", - "version": "7.85.0", + "version": "7.87.0", "declared_directly": true }, { @@ -249,12 +258,12 @@ }, { "full_name": "freetds", - "version": "1.3.13", + "version": "1.3.17", "declared_directly": true }, { "full_name": "libpng", - "version": "1.6.37", + "version": "1.6.39", "declared_directly": false }, { @@ -264,12 +273,12 @@ }, { "full_name": "fontconfig", - "version": "2.14.0", + "version": "2.14.2", "declared_directly": false }, { "full_name": "jpeg-turbo", - "version": "2.1.4", + "version": "2.1.5", "declared_directly": false }, { @@ -278,13 +287,13 @@ "declared_directly": false }, { - "full_name": "imath", - "version": "3.1.5", + "full_name": "highway", + "version": "1.0.3", "declared_directly": false }, { - "full_name": "openexr", - "version": "3.1.5", + "full_name": "imath", + "version": "3.1.6", "declared_directly": false }, { @@ -292,14 +301,24 @@ "version": "4.4.0", "declared_directly": false }, + { + "full_name": "little-cms2", + "version": "2.14", + "declared_directly": false + }, + { + "full_name": "openexr", + "version": "3.1.5", + "declared_directly": false + }, { "full_name": "webp", - "version": "1.2.4", + "version": "1.3.0", "declared_directly": false }, { "full_name": "jpeg-xl", - "version": "0.6.1", + "version": "0.8.1", "declared_directly": false }, { @@ -309,12 +328,12 @@ }, { "full_name": "aom", - "version": "3.4.0", + "version": "3.5.0", "declared_directly": false }, { "full_name": "libavif", - "version": "0.10.1", + "version": "0.11.1", "declared_directly": false }, { @@ -329,17 +348,17 @@ }, { "full_name": "icu4c", - "version": "71.1", + "version": "72.1", "declared_directly": true }, { "full_name": "krb5", - "version": "1.20", + "version": "1.20.1", "declared_directly": true }, { "full_name": "libpq", - "version": "14.5", + "version": "15.1", "declared_directly": true }, { @@ -359,17 +378,17 @@ }, { "full_name": "pcre2", - "version": "10.40", + "version": "10.42", "declared_directly": true }, { "full_name": "readline", - "version": "8.1.2", + "version": "8.2.1", "declared_directly": false }, { "full_name": "sqlite", - "version": "3.39.2", + "version": "3.40.1", "declared_directly": true }, { @@ -382,7 +401,7 @@ "installed_on_request": true } ], - "linked_keg": "8.1.10_1", + "linked_keg": "8.2.2", "pinned": false, "outdated": false, "deprecated": false, @@ -390,6 +409,8 @@ "deprecation_reason": null, "disabled": false, "disable_date": null, - "disable_reason": null + "disable_reason": null, + "tap_git_head": "0bbb89420e74756a5a5c145ed7efa4a32f7e7e7c" } - ] + +] From f27e07fc78b2162147d9e6793b4a6a62676894bc Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Mon, 13 Feb 2023 17:30:37 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=94=A7=20Bump=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 16 ++++++++-------- .../DomainList/Cells/DomainListPhpCell.swift | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 2c8a53d..aa9e324 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -2831,7 +2831,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1037; + CURRENT_PROJECT_VERSION = 1040; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -2843,7 +2843,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 5.7.3; + MARKETING_VERSION = 5.7.4; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2860,7 +2860,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1037; + CURRENT_PROJECT_VERSION = 1040; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -2872,7 +2872,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 5.7.3; + MARKETING_VERSION = 5.7.4; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3088,7 +3088,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1037; + CURRENT_PROJECT_VERSION = 1040; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3099,7 +3099,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 5.7.3; + MARKETING_VERSION = 5.7.4; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev; PRODUCT_NAME = "$(TARGET_NAME) DEV"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3198,7 +3198,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1037; + CURRENT_PROJECT_VERSION = 1040; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3209,7 +3209,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 5.7.3; + MARKETING_VERSION = 5.7.4; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/phpmon/Domain/DomainList/Cells/DomainListPhpCell.swift b/phpmon/Domain/DomainList/Cells/DomainListPhpCell.swift index 9271a29..9d2d73c 100644 --- a/phpmon/Domain/DomainList/Cells/DomainListPhpCell.swift +++ b/phpmon/Domain/DomainList/Cells/DomainListPhpCell.swift @@ -37,7 +37,8 @@ class DomainListPhpCell: NSTableCellView, DomainListCellProtocol { imageViewPhpVersionOK.image = NSImage(named: "Isolated") imageViewPhpVersionOK.toolTip = "domain_list.tooltips.isolated".localized(site.servingPhpVersion) } else { - imageViewPhpVersionOK.isHidden = (site.preferredPhpVersion == "???" || !site.isCompatibleWithPreferredPhpVersion) + imageViewPhpVersionOK.isHidden = (site.preferredPhpVersion == "???" + || !site.isCompatibleWithPreferredPhpVersion) imageViewPhpVersionOK.image = NSImage(named: "Checkmark") imageViewPhpVersionOK.toolTip = "domain_list.tooltips.checkmark".localized(site.preferredPhpVersion) From 3f14754177508e8940172419097fe1e07b8fa5bb Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 21 Feb 2023 18:17:24 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=93=9D=20Update=20README=20to=20refle?= =?UTF-8?q?ct=20#239?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- SECURITY.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e467e1a..014928b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You can also add new domains as links, isolate sites, manage various services, a PHP Monitor is a universal application that runs natively on Apple Silicon **and** Intel-based Macs. * Your user account can administer your computer (required for some functionality, e.g. certificate generation) -* macOS 11 Big Sur or later +* macOS Monterey 12.4 or later (Ventura supported) * Homebrew is installed in `/usr/local/homebrew` or `/opt/homebrew` * Homebrew `php` formula is installed * Laravel Valet (works with Valet v2, v3 and v4) diff --git a/SECURITY.md b/SECURITY.md index 2255dca..11a15e1 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,7 +6,7 @@ Generally speaking, only the latest version of **PHP Monitor** is supported, exc | Version | Apple Silicon | Supported | Supported macOS | Deployment Target | Detected PHP Versions | Recommended Valet Version | | ------- | ------------- | ------------------ | ----- | ----- | ----- | ---- -| 5.7 | ✅ Universal binary | ✅ Yes | Big Sur (11.0)
Monterey (12.0)
Ventura (13.0) | macOS 11+ | PHP 5.6—PHP 8.2 (w/ Valet 2.x)
PHP 7.0—PHP 8.2 (w/ Valet 3.x)
PHP 7.1-PHP 8.2 (w/ Valet 4.x*) | 3.0 or higher recommended
2.16.2 minimum | +| 5.7 | ✅ Universal binary | ✅ Yes | Monterey (12.4+)
Ventura (13.0) | macOS 11+ | PHP 5.6—PHP 8.2 (w/ Valet 2.x)
PHP 7.0—PHP 8.2 (w/ Valet 3.x)
PHP 7.1-PHP 8.2 (w/ Valet 4.x*) | 3.0 or higher recommended
2.16.2 minimum | (*) Preliminary listing. Valet 4 hasn't been released yet and the versions of PHP Valet can work with might still change. From 127d5f44948d621387278c6425764353151ae4c6 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 3 Mar 2023 23:11:40 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=85=20Improve=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 4 + phpmon/Common/PHP/PHP Version/PhpHelper.swift | 18 ++-- .../Testables/TestableConfiguration.swift | 84 +++++++++++++++++++ tests/Shared/TestableConfigurations.swift | 39 ++------- tests/ui/MainMenuTest.swift | 50 +++++++++++ tests/ui/StartupTest.swift | 31 +------ tests/ui/UITestCase.swift | 9 +- 7 files changed, 166 insertions(+), 69 deletions(-) create mode 100644 tests/ui/MainMenuTest.swift diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 985dacc..d2060d1 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -587,6 +587,7 @@ C4C8E819276F54D8003AC782 /* App+ConfigWatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C8E817276F54D8003AC782 /* App+ConfigWatch.swift */; }; C4C8E81B276F54E5003AC782 /* PhpConfigWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C8E81A276F54E5003AC782 /* PhpConfigWatcher.swift */; }; C4C8E81C276F54E5003AC782 /* PhpConfigWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C8E81A276F54E5003AC782 /* PhpConfigWatcher.swift */; }; + C4CB250529B28BB800CA4492 /* MainMenuTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CB250429B28BB800CA4492 /* MainMenuTest.swift */; }; C4CB6E65292C362C002E9027 /* Homebrew.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CB6E64292C362C002E9027 /* Homebrew.swift */; }; C4CB6E66292C362C002E9027 /* Homebrew.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CB6E64292C362C002E9027 /* Homebrew.swift */; }; C4CB6E67292C362C002E9027 /* Homebrew.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4CB6E64292C362C002E9027 /* Homebrew.swift */; }; @@ -915,6 +916,7 @@ C4C8900628F0E3EF00CE5E97 /* ActiveFileSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveFileSystem.swift; sourceTree = ""; }; C4C8E817276F54D8003AC782 /* App+ConfigWatch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "App+ConfigWatch.swift"; sourceTree = ""; }; C4C8E81A276F54E5003AC782 /* PhpConfigWatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhpConfigWatcher.swift; sourceTree = ""; }; + C4CB250429B28BB800CA4492 /* MainMenuTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuTest.swift; sourceTree = ""; }; C4CB6E64292C362C002E9027 /* Homebrew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Homebrew.swift; sourceTree = ""; }; C4CCBA6B275C567B008C7055 /* PMWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PMWindowController.swift; sourceTree = ""; }; C4CDA892288F1A71007CE25F /* Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keys.swift; sourceTree = ""; }; @@ -1432,6 +1434,7 @@ C469E702294CFDF700A82AB2 /* DomainsListTest.swift */, C44E985E29B23EBF0059F773 /* UpdateCheckTest.swift */, C4181F1028FAF9330042EA28 /* UITestCase.swift */, + C4CB250429B28BB800CA4492 /* MainMenuTest.swift */, ); path = ui; sourceTree = ""; @@ -2455,6 +2458,7 @@ C471E8DC28F9BB8F0021E251 /* ProgressVC.swift in Sources */, C471E8DE28F9BB8F0021E251 /* App+ConfigWatch.swift in Sources */, C471E8DF28F9BB8F0021E251 /* PhpConfigWatcher.swift in Sources */, + C4CB250529B28BB800CA4492 /* MainMenuTest.swift in Sources */, C471E8E028F9BB8F0021E251 /* Preset.swift in Sources */, C471E8E128F9BB8F0021E251 /* PresetHelper.swift in Sources */, C471E8E228F9BB8F0021E251 /* WarningView.swift in Sources */, diff --git a/phpmon/Common/PHP/PHP Version/PhpHelper.swift b/phpmon/Common/PHP/PHP Version/PhpHelper.swift index 75aa912..b248bb1 100644 --- a/phpmon/Common/PHP/PHP Version/PhpHelper.swift +++ b/phpmon/Common/PHP/PHP Version/PhpHelper.swift @@ -28,10 +28,12 @@ class PhpHelper { Task { // Create the appropriate folders and check if the files exist do { if !FileSystem.directoryExists("~/.config/phpmon/bin") { - try FileSystem.createDirectory( - "~/.config/phpmon/bin", - withIntermediateDirectories: true - ) + Task { @MainActor in + try FileSystem.createDirectory( + "~/.config/phpmon/bin", + withIntermediateDirectories: true + ) + } } if FileSystem.fileExists(destination) { @@ -59,10 +61,12 @@ class PhpHelper { export PATH=\(path):$PATH """ - try FileSystem.writeAtomicallyToFile(destination, content: script) + Task { @MainActor in + try FileSystem.writeAtomicallyToFile(destination, content: script) - if !FileSystem.isExecutableFile(destination) { - try FileSystem.makeExecutable(destination) + if !FileSystem.isExecutableFile(destination) { + try FileSystem.makeExecutable(destination) + } } // Create a symlink if the folder is not in the PATH diff --git a/phpmon/Common/Testables/TestableConfiguration.swift b/phpmon/Common/Testables/TestableConfiguration.swift index 2dbb33e..d509619 100644 --- a/phpmon/Common/Testables/TestableConfiguration.swift +++ b/phpmon/Common/Testables/TestableConfiguration.swift @@ -15,6 +15,88 @@ public struct TestableConfiguration: Codable { var commandOutput: [String: String] var preferenceOverrides: [PreferenceName: Bool] + init( + architecture: String, + filesystem: [String: FakeFile], + shellOutput: [String: BatchFakeShellOutput], + commandOutput: [String: String], + preferenceOverrides: [PreferenceName: Bool], + phpVersions: [VersionNumber] + ) { + self.architecture = architecture + self.filesystem = filesystem + self.shellOutput = shellOutput + self.commandOutput = commandOutput + self.preferenceOverrides = preferenceOverrides + + phpVersions.enumerated().forEach { (index, version) in + self.addPhpVersion(version, primary: index == 0) + } + } + + private enum CodingKeys: String, CodingKey { + case architecture, filesystem, shellOutput, commandOutput, preferenceOverrides + } + + // MARK: Add PHP versions + + private var primaryPhpVersion: VersionNumber? + private var secondaryPhpVersions: [VersionNumber] = [] + + mutating func addPhpVersion(_ version: VersionNumber, primary: Bool) { + if primary { + if primaryPhpVersion != nil { + fatalError("You cannot add multiple primary PHP versions to a testable configuration!") + } + primaryPhpVersion = version + } else { + self.secondaryPhpVersions.append(version) + } + + self.filesystem = self.filesystem.merging([ + "/opt/homebrew/opt/php@\(version.short)/bin/php" + : .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)/bin/php"), + "/opt/homebrew/Cellar/php/\(version.long)/bin/php" + : .fake(.binary), + "/opt/homebrew/Cellar/php/\(version.long)/bin/php-config" + : .fake(.binary), + "/opt/homebrew/etc/php/\(version.short)/php-fpm.d/www.conf" + : .fake(.text), + "/opt/homebrew/etc/php/\(version.short)/php-fpm.d/valet-fpm.conf" + : .fake(.text), + "/opt/homebrew/etc/php/\(version.short)/php.ini" + : .fake(.text), + "/opt/homebrew/etc/php/\(version.short)/conf.d/php-memory-limits.ini" + : .fake(.text) + ]) { (_, new) in new } + + if primary { + self.shellOutput["ls /opt/homebrew/opt | grep php"] + = .instant("php") + self.filesystem["/opt/homebrew/opt/php"] + = .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)") + self.filesystem["/opt/homebrew/opt/php/bin/php"] + = .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)/bin/php") + self.filesystem["/opt/homebrew/bin/php"] + = .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)/bin/php") + self.commandOutput["/opt/homebrew/bin/php-config --version"] + = version.long + self.commandOutput["/opt/homebrew/bin/php -r echo php_ini_scanned_files();"] = + """ + /opt/homebrew/etc/php/\(version.short)/conf.d/php-memory-limits.ini, + """ + } else { + self.shellOutput["ls /opt/homebrew/opt | grep php@"] = + BatchFakeShellOutput.instant( + self.secondaryPhpVersions + .map { "php@\($0.short)" } + .joined(separator: "\n") + ) + } + } + + // MARK: Interactions + func apply() { Log.separator() Log.info("USING TESTABLE CONFIGURATION...") @@ -38,6 +120,8 @@ public struct TestableConfiguration: Codable { } } + // MARK: Persist and load + func toJson(pretty: Bool = false) -> String { let data = try! JSONEncoder().encode(self) diff --git a/tests/Shared/TestableConfigurations.swift b/tests/Shared/TestableConfigurations.swift index e2b8ce0..4c105bb 100644 --- a/tests/Shared/TestableConfigurations.swift +++ b/tests/Shared/TestableConfigurations.swift @@ -24,16 +24,6 @@ class TestableConfigurations { : .fake(.binary), "/opt/homebrew/bin/valet" : .fake(.binary), - "/opt/homebrew/opt/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.2.0/bin/php-config" - : .fake(.binary), - "/opt/homebrew/etc/php/8.2/php-fpm.d/www.conf" - : .fake(.text), "~/.config/valet/config.json" : .fake(.text, """ { @@ -45,12 +35,6 @@ class TestableConfigurations { "loopback": "127.0.0.1" } """), - "/opt/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf" - : .fake(.text), - "/opt/homebrew/etc/php/8.2/php.ini" - : .fake(.text), - "/opt/homebrew/etc/php/8.2/conf.d/php-memory-limits.ini" - : .fake(.text) ], shellOutput: [ "sysctl -n sysctl.proc_translated" @@ -59,17 +43,6 @@ class TestableConfigurations { : .instant("user"), "which node" : .instant("/opt/homebrew/bin/node"), - "php -v" - : .instant(""" - PHP 8.2.0 (cli) (built: Dec XX 20XX XX:XX:XX) (NTS) - Copyright (c) The PHP Group - 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.2"), "sudo /opt/homebrew/bin/brew services info dnsmasq --json" : .delayed(0.2, """ [ @@ -176,16 +149,16 @@ class TestableConfigurations { : .instant("OK"), ], commandOutput: [ - "/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.2/conf.d/php-memory-limits.ini, - """ ], - preferenceOverrides: [:] + preferenceOverrides: [:], + phpVersions: [ + VersionNumber(major: 8, minor: 2, patch: 0), + VersionNumber(major: 8, minor: 1, patch: 0), + VersionNumber(major: 8, minor: 0, patch: 0) + ] ) } } diff --git a/tests/ui/MainMenuTest.swift b/tests/ui/MainMenuTest.swift new file mode 100644 index 0000000..5c3f2b3 --- /dev/null +++ b/tests/ui/MainMenuTest.swift @@ -0,0 +1,50 @@ +// +// MainMenuTest.swift +// UI Tests +// +// Created by Nico Verbruggen on 03/03/2023. +// Copyright © 2023 Nico Verbruggen. All rights reserved. +// + +import XCTest + +final class MainMenuTest: UITestCase { + + override func setUpWithError() throws { + continueAfterFailure = false + } + + final func test_can_open_status_menu_item() throws { + let app = launch(openMenu: true) + + assertAllExist([ + // "Switch to PHP 8.2 (php)" should be visible since it is aliased to `php` + app.menuItems["\("mi_php_switch".localized) 8.2 (php)"], + // "Switch to PHP 8.1" should be the non-disabled option + app.menuItems["\("mi_php_switch".localized) 8.1 (php@8.1)"], + // "Switch to PHP 8.0" should be the non-disabled option + app.menuItems["\("mi_php_switch".localized) 8.0 (php@8.0)"], + // We should see the about and quit items + app.menuItems["mi_about".localized], + app.menuItems["mi_quit".localized] + ]) + + sleep(2) + } + + final func test_can_open_about() throws { + let app = launch(openMenu: true) + app.mainMenuItem(withText: "mi_about".localized).click() + } + + final func test_can_open_settings() throws { + let app = launch(openMenu: true) + app.mainMenuItem(withText: "mi_preferences".localized).click() + } + + final func test_can_quit_app() throws { + let app = launch(openMenu: true) + app.mainMenuItem(withText: "mi_quit".localized).click() + } + +} diff --git a/tests/ui/StartupTest.swift b/tests/ui/StartupTest.swift index 369cf26..2c00802 100644 --- a/tests/ui/StartupTest.swift +++ b/tests/ui/StartupTest.swift @@ -20,9 +20,7 @@ final class StartupTest: UITestCase { var configuration = TestableConfigurations.working configuration.filesystem["/opt/homebrew/bin/php"] = nil // PHP binary must be missing - let app = XCPMApplication() - app.withConfiguration(configuration) - app.launch() + let app = launch(with: configuration) // Dialog 1: "PHP is not correctly installed" assertAllExist([ @@ -52,9 +50,7 @@ final class StartupTest: UITestCase { var configuration = TestableConfigurations.working configuration.filesystem["/opt/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf"] = nil - let app = XCPMApplication() - app.withConfiguration(configuration) - app.launch() + let app = launch(with: configuration) assertExists(app.staticTexts["alert.php_fpm_broken.title".localized], 3.0) click(app.buttons["generic.ok".localized]) @@ -64,30 +60,9 @@ final class StartupTest: UITestCase { var configuration = TestableConfigurations.working configuration.shellOutput["valet --version"] = .instant("Laravel Valet 5.0") - let app = XCPMApplication() - app.withConfiguration(configuration) - app.launch() + let app = launch(with: configuration) assertExists(app.staticTexts["startup.errors.valet_version_not_supported.title".localized], 3.0) click(app.buttons["generic.ok".localized]) } - - final func test_can_open_status_menu_item() throws { - let app = XCPMApplication() - app.withConfiguration(TestableConfigurations.working) - app.launch() - - // Note: If this fails here, make sure the menu bar item can be displayed - // If you use Bartender or something like this, this item may be hidden and tests will fail - app.statusItems.firstMatch.click() - - assertAllExist([ - // "Switch to PHP 8.1 (php)" should be visible since it is aliased to `php` - app.menuItems["\("mi_php_switch".localized) 8.2 (php)"], - // We should see the about and quit items - app.menuItems["mi_about".localized], - app.menuItems["mi_quit".localized] - ]) - sleep(2) - } } diff --git a/tests/ui/UITestCase.swift b/tests/ui/UITestCase.swift index 858b824..4a02651 100644 --- a/tests/ui/UITestCase.swift +++ b/tests/ui/UITestCase.swift @@ -9,7 +9,6 @@ import XCTest class UITestCase: XCTestCase { - /** Launches the app and opens the menu. */ public func launch( openMenu: Bool = false, @@ -50,7 +49,15 @@ class UITestCase: XCTestCase { public func click(_ element: XCUIElement) { element.click() } +} +extension XCPMApplication { + /** + Opens a given menu item found in the menu bar's status item. + */ + public func mainMenuItem(withText text: String) -> XCUIElement { + self.statusItems.firstMatch.menuItems[text].firstMatch + } } extension XCUIElement {