mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-26 06:00:07 +01:00
✅ Ensure tests pass without waiting for initialization
This commit is contained in:
@@ -123,6 +123,9 @@ extension Startup {
|
||||
// Mark app as having successfully booted passing all checks
|
||||
Startup.hasFinishedBooting = true
|
||||
|
||||
// Enable the main menu item
|
||||
MainMenu.shared.statusItem.button?.isEnabled = true
|
||||
|
||||
// Post-launch stats and update check, but only if not running tests
|
||||
await performPostLaunchActions()
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
|
||||
})
|
||||
statusItem.menu = menu
|
||||
statusItem.menu?.delegate = self
|
||||
statusItem.button?.isEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ final class StartupTest: UITestCase {
|
||||
var configuration = TestableConfigurations.working
|
||||
configuration.filesystem["/opt/homebrew/bin/php"] = nil // PHP binary must be missing
|
||||
|
||||
let app = launch(with: configuration)
|
||||
let app = launch(
|
||||
waitForInitialization: false, // we expect an error during initialization
|
||||
with: configuration
|
||||
)
|
||||
|
||||
// Dialog 1: "PHP is not correctly installed"
|
||||
assertAllExist([
|
||||
@@ -50,7 +53,10 @@ final class StartupTest: UITestCase {
|
||||
var configuration = TestableConfigurations.working
|
||||
configuration.filesystem["/opt/homebrew/etc/php/8.4/php-fpm.d/valet-fpm.conf"] = nil
|
||||
|
||||
let app = launch(with: configuration)
|
||||
let app = launch(
|
||||
waitForInitialization: false, // we expect an error during initialization
|
||||
with: configuration
|
||||
)
|
||||
|
||||
assertExists(app.staticTexts["alert.php_fpm_broken.title".localized], 3.0)
|
||||
click(app.buttons["generic.ok".localized])
|
||||
@@ -60,7 +66,10 @@ final class StartupTest: UITestCase {
|
||||
var configuration = TestableConfigurations.working
|
||||
configuration.shellOutput["valet --version"] = .instant("Laravel Valet 5.0")
|
||||
|
||||
let app = launch(with: configuration)
|
||||
let app = launch(
|
||||
waitForInitialization: false, // we expect an error during initialization
|
||||
with: configuration
|
||||
)
|
||||
|
||||
assertExists(app.staticTexts["startup.errors.valet_version_not_supported.title".localized], 3.0)
|
||||
click(app.buttons["generic.ok".localized])
|
||||
|
||||
@@ -9,31 +9,41 @@
|
||||
import XCTest
|
||||
|
||||
class UITestCase: XCTestCase {
|
||||
/** Launches the app and opens the menu. */
|
||||
/**
|
||||
Launches the app and opens the menu.
|
||||
Defaults to waiting for the app to finish initialization.
|
||||
|
||||
- Parameter waitForInitialization: Waits for the PHP Monitor to pass the environment checks (startup).
|
||||
- Parameter openMenu: Attempts to open the status menu when ready; requires passing environment checks.
|
||||
- Parameter configuration: The TestableConfiguration to include when launching PHP Monitor.
|
||||
*/
|
||||
public func launch(
|
||||
waitForInitialization: Bool = true,
|
||||
openMenu: Bool = false,
|
||||
with configuration: TestableConfiguration? = nil
|
||||
with configuration: TestableConfiguration? = nil,
|
||||
) -> XCPMApplication {
|
||||
let app = XCPMApplication()
|
||||
let config = configuration ?? TestableConfigurations.working
|
||||
app.withConfiguration(config)
|
||||
app.launch()
|
||||
|
||||
let statusItem = app.statusItems.firstMatch
|
||||
let isEnabled = NSPredicate(format: "isEnabled == true")
|
||||
let expectation = expectation(for: isEnabled, evaluatedWith: statusItem, handler: nil)
|
||||
let result = XCTWaiter().wait(for: [expectation], timeout: 15)
|
||||
if waitForInitialization || openMenu {
|
||||
let statusItem = app.statusItems.firstMatch
|
||||
let isEnabled = NSPredicate(format: "isEnabled == true")
|
||||
let expectation = expectation(for: isEnabled, evaluatedWith: statusItem, handler: nil)
|
||||
let result = XCTWaiter().wait(for: [expectation], timeout: 15)
|
||||
|
||||
if result == .timedOut {
|
||||
XCTFail("PHP Monitor did not initialize with an available UI element within 15 seconds.")
|
||||
if result == .timedOut {
|
||||
XCTFail("PHP Monitor did not initialize with an available UI element within 15 seconds.")
|
||||
}
|
||||
|
||||
if openMenu {
|
||||
statusItem.click()
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
if openMenu {
|
||||
statusItem.click()
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user