1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

🔀 Merge branch 'dev/5.8-tests' into dev/6.0

This commit is contained in:
2023-03-04 00:29:57 +01:00
8 changed files with 176 additions and 213 deletions

View File

@ -22,20 +22,8 @@ class TestableConfigurations {
: .fake(.binary),
"/opt/homebrew/bin/php"
: .fake(.binary),
"/opt/homebrew/bin/php-config"
: .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, """
{
@ -47,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"
@ -61,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, """
[
@ -145,10 +116,10 @@ class TestableConfigurations {
cask 'phpmon-dev' do
depends_on formula: 'gnu-sed'
version '\(App.shortVersion)_\(App.bundleVersion)'
version '6.0.0_2000'
sha256 '1cb147bd1b1fbd52971d90dff577465b644aee7c878f15ede57f46e8f217067a'
url 'https://github.com/nicoverbruggen/phpmon/releases/download/v\(App.shortVersion)/phpmon-dev.zip'
url 'https://github.com/nicoverbruggen/phpmon/releases/download/v6.0/phpmon-dev.zip'
appcast 'https://github.com/nicoverbruggen/phpmon/releases.atom'
name 'PHP Monitor DEV'
homepage 'https://phpmon.app'
@ -178,158 +149,27 @@ 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: [
.automaticBackgroundUpdateCheck: false
],
phpVersions: [
VersionNumber(major: 8, minor: 2, patch: 0),
VersionNumber(major: 8, minor: 1, patch: 0),
VersionNumber(major: 8, minor: 0, patch: 0)
]
)
}
/** A functional, working system setup (but without Valet). */
static var workingWithoutValet: TestableConfiguration {
return TestableConfiguration(
architecture: "arm64",
filesystem: [
"/usr/local/bin/"
: .fake(.directory, readOnly: true),
"/usr/local/bin/composer"
: .fake(.binary),
"/opt/homebrew/bin/brew"
: .fake(.binary),
"/opt/homebrew/bin/php"
: .fake(.binary),
"/opt/homebrew/bin/php-config"
: .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),
"/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"
: .instant("0"),
"id -un"
: .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, """
[
{
"name": "nginx",
"service_name": "homebrew.mxcl.nginx",
"running": true,
"loaded": true,
"schedulable": false,
"pid": 133,
"exit_code": 0,
"user": "root",
"status": "started",
"file": "/Library/LaunchDaemons/homebrew.mxcl.nginx.plist",
"command": "/opt/homebrew/opt/nginx/bin/nginx -g daemon off;",
"working_dir": "/opt/homebrew",
"root_dir": null,
"log_path": null,
"error_log_path": null,
"interval": null,
"cron": null
}
]
"""),
"/opt/homebrew/bin/brew tap"
: .instant("""
homebrew/cask
homebrew/core
homebrew/services
nicoverbruggen/cask
shivammathur/php
"""),
"chmod +x /Users/nicoverbruggen/.config/phpmon/bin/pm82"
: .instant(""),
"mkdir -p ~/.config/phpmon"
: .instant(""),
"mkdir -p ~/.config/phpmon/bin"
: .instant(""),
"brew info shivammathur/php/php --json"
: .instant("Error: No available formula with the name \"shivammathur/php/php\"."),
"/usr/bin/open -Ra \"PhpStorm\""
: .instant("Unable to find application named 'PhpStorm'", .stdErr),
"/usr/bin/open -Ra \"Visual Studio Code\""
: .instant("Unable to find application named 'Visual Studio Code'", .stdErr),
"/usr/bin/open -Ra \"Sublime Text\""
: .instant("Unable to find application named 'Sublime Text'", .stdErr),
"/usr/bin/open -Ra \"Sublime Merge\""
: .instant("Unable to find application named 'Sublime Merge'", .stdErr),
"/usr/bin/open -Ra \"iTerm\""
: .instant("Unable to find application named 'iTerm'", .stdErr),
"/opt/homebrew/bin/brew info php --json"
: .instant(ShellStrings.shared.brewJson),
"sudo /opt/homebrew/bin/brew services info --all --json"
: .instant(ShellStrings.shared.brewServicesAsRoot),
"/opt/homebrew/bin/brew services info --all --json"
: .instant(ShellStrings.shared.brewServicesAsUser),
"curl -s --max-time 5 '\(Constants.Urls.StableBuildCaskFile.absoluteString)' | grep version"
: .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"
: .delayed(0.2, "OK"),
"sudo /opt/homebrew/bin/brew services start php"
: .delayed(0.2, "OK"),
"sudo /opt/homebrew/bin/brew services stop nginx"
: .delayed(0.2, "OK"),
"sudo /opt/homebrew/bin/brew services start nginx"
: .delayed(0.2, "OK"),
"sudo /opt/homebrew/bin/brew services stop dnsmasq"
: .delayed(0.2, "OK"),
"sudo /opt/homebrew/bin/brew services start dnsmasq"
: .delayed(0.2, "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: [
: // TODO: Add default preferences that are relevant for tests
]
)
var configuration = TestableConfigurations.working
configuration.filesystem["/opt/homebrew/bin/valet"] = nil
configuration.filesystem["~/.config/valet/config.json"] = nil
return configuration
}
}

View File

@ -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()
}
}

View File

@ -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)
}
}

View File

@ -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 {