From e40b9fe45a75fe28a25e2241590c847e0aa55c63 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sun, 10 Sep 2023 11:14:38 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20UI=20test=20for=20PHP=20versi?= =?UTF-8?q?on=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Testables/TestableConfiguration.swift | 18 ++++++++----- .../Homebrew/BrewFormulaeHandler.swift | 1 + tests/Shared/TestableConfigurations.swift | 18 ++++++++++++- tests/ui/MainMenuTest.swift | 25 +++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/phpmon/Common/Testables/TestableConfiguration.swift b/phpmon/Common/Testables/TestableConfiguration.swift index bdcb206..95e1423 100644 --- a/phpmon/Common/Testables/TestableConfiguration.swift +++ b/phpmon/Common/Testables/TestableConfiguration.swift @@ -56,6 +56,8 @@ public struct TestableConfiguration: Codable { 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/opt/php@\(version.short)/bin/php-config" + : .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)/bin/php-config"), "/opt/homebrew/Cellar/php/\(version.long)/bin/php" : .fake(.binary), "/opt/homebrew/Cellar/php/\(version.long)/bin/php-config" @@ -70,6 +72,9 @@ public struct TestableConfiguration: Codable { : .fake(.text) ]) { (_, new) in new } + self.commandOutput["/opt/homebrew/opt/php@\(version.short)/bin/php-config --version"] + = version.long + if primary { self.shellOutput["ls /opt/homebrew/opt | grep php"] = .instant("php") @@ -80,7 +85,7 @@ public struct TestableConfiguration: Codable { self.filesystem["/opt/homebrew/bin/php"] = .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)/bin/php") self.filesystem["/opt/homebrew/bin/php-config"] - = .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.long)/bin/php-config") + = .fake(.symlink, "/opt/homebrew/Cellar/php/\(version.short)/bin/php-config") self.commandOutput["/opt/homebrew/bin/php-config --version"] = version.long self.commandOutput["/opt/homebrew/bin/php -r echo php_ini_scanned_files();"] = @@ -88,12 +93,13 @@ public struct TestableConfiguration: Codable { /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") - ) + BatchFakeShellOutput.instant( + self.secondaryPhpVersions + .map { "php@\($0.short)" } + .joined(separator: "\n") + ) } } diff --git a/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift b/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift index 83cddc8..c645ead 100644 --- a/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift +++ b/phpmon/Domain/Integrations/Homebrew/BrewFormulaeHandler.swift @@ -44,6 +44,7 @@ class BrewFormulaeHandler: HandlesBrewFormulae { return Brew.phpVersionFormulae.map { (version, formula) in let fullVersion = PhpEnvironments.shared.cachedPhpInstallations[version]?.versionNumber.text + var upgradeVersion: String? if let version = fullVersion { diff --git a/tests/Shared/TestableConfigurations.swift b/tests/Shared/TestableConfigurations.swift index 4652f46..6a7eff1 100644 --- a/tests/Shared/TestableConfigurations.swift +++ b/tests/Shared/TestableConfigurations.swift @@ -160,6 +160,22 @@ class TestableConfigurations { : .delayed(0.2, "OK"), "ln -sF ~/.config/valet/valet82.sock ~/.config/valet/valet.sock" : .instant("OK"), + "/opt/homebrew/bin/brew update >/dev/null && /opt/homebrew/bin/brew outdated --json --formulae": .delayed(2.0, """ + { + "formulae": [ + { + "name": "php", + "installed_versions": [ + "8.2.6" + ], + "current_version": "8.2.11", + "pinned": false, + "pinned_version": null + } + ], + "casks": [] + } + """) ], commandOutput: [ "/opt/homebrew/bin/php -r echo ini_get('memory_limit');": "512M", @@ -173,7 +189,7 @@ class TestableConfigurations { .automaticBackgroundUpdateCheck: false ], phpVersions: [ - VersionNumber(major: 8, minor: 2, patch: 0), + VersionNumber(major: 8, minor: 2, patch: 6), 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 index 7589554..2c459fc 100644 --- a/tests/ui/MainMenuTest.swift +++ b/tests/ui/MainMenuTest.swift @@ -71,6 +71,31 @@ final class MainMenuTest: UITestCase { click(app.buttons["Notifications"]) } + final func test_can_open_php_version_manager() throws { + let app = launch(openMenu: true) + app.mainMenuItem(withText: "mi_php_version_manager".localized).click() + + // Should display loader + assertExists(app.staticTexts["phpman.busy.title".localized], 1) + + // After loading, should display PHP 8.2 + assertExists(app.staticTexts["PHP 8.2"], 5) + + // Should also display pre-release version + assertExists(app.staticTexts["PHP 8.3"]) + assertExists(app.staticTexts["phpman.version.prerelease".localized.uppercased()]) + assertExists(app.staticTexts["phpman.version.available_for_installation".localized]) + + // But not PHP 8.4 (yet) + assertNotExists(app.staticTexts["PHP 8.4"]) + + // Also, PHP 8.2 should have an update available + assertExists(app.staticTexts["phpman.version.has_update".localized( + "8.2.6", + "8.2.11" + )], 5) + } + final func test_can_quit_app() throws { let app = launch(openMenu: true) app.mainMenuItem(withText: "mi_quit".localized).click()