1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-12-25 12:30:08 +01:00

Fix tests, new shell in various places

This commit is contained in:
2022-10-05 01:06:52 +02:00
parent 3267dc8add
commit fb1ca60240
7 changed files with 268 additions and 326 deletions

View File

@@ -25,9 +25,9 @@ class HomebrewPackageTest: XCTestCase {
XCTAssertEqual(package.name, "php") XCTAssertEqual(package.name, "php")
XCTAssertEqual(package.full_name, "php") XCTAssertEqual(package.full_name, "php")
XCTAssertEqual(package.aliases.first!, "php@8.0") XCTAssertEqual(package.aliases.first!, "php@8.1")
XCTAssertEqual(package.installed.contains(where: { installed in XCTAssertEqual(package.installed.contains(where: { installed in
installed.version.starts(with: "8.0") installed.version.starts(with: "8.1")
}), true) }), true)
} }

View File

@@ -1,70 +1,83 @@
[ [
{ {
"name":"php", "name": "php",
"full_name":"php", "full_name": "php",
"tap":"homebrew/core", "tap": "homebrew/core",
"oldname":null, "oldname": null,
"aliases":[ "aliases": [
"php@8.0" "php@8.1"
], ],
"versioned_formulae":[ "versioned_formulae": [
"php@8.0",
"php@7.4", "php@7.4",
"php@7.3", "php@7.3",
"php@7.2" "php@7.2"
], ],
"desc":"General-purpose scripting language", "desc": "General-purpose scripting language",
"license":"PHP-3.01", "license": "PHP-3.01",
"homepage":"https://www.php.net/", "homepage": "https://www.php.net/",
"versions":{ "versions": {
"stable":"8.0.2", "stable": "8.1.10",
"head":"HEAD", "head": "HEAD",
"bottle":true "bottle": true
}, },
"urls":{ "urls": {
"stable":{ "stable": {
"url":"https://www.php.net/distributions/php-8.0.2.tar.xz", "url": "https://www.php.net/distributions/php-8.1.10.tar.xz",
"tag":null, "tag": null,
"revision":null "revision": null
} }
}, },
"revision":0, "revision": 1,
"version_scheme":0, "version_scheme": 0,
"bottle":{ "bottle": {
"stable":{ "stable": {
"rebuild":0, "rebuild": 0,
"cellar":"/opt/homebrew/Cellar", "root_url": "https://ghcr.io/v2/homebrew/core",
"prefix":"/opt/homebrew", "files": {
"root_url":"https://homebrew.bintray.com/bottles", "arm64_monterey": {
"files":{ "cellar": "/opt/homebrew/Cellar",
"arm64_big_sur":{ "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:dcee33c9f445db3026a7e867805eb8f6d82e9e5599599b8c6cd8645475f7961c",
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.arm64_big_sur.bottle.tar.gz", "sha256": "dcee33c9f445db3026a7e867805eb8f6d82e9e5599599b8c6cd8645475f7961c"
"sha256":"cbefa1db73d08b9af4593a44512b8d727e43033ee8517736bae5f16315501b12"
}, },
"big_sur":{ "arm64_big_sur": {
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.big_sur.bottle.tar.gz", "cellar": "/opt/homebrew/Cellar",
"sha256":"6857142e12254b15da4e74c2986dd24faca57dac8d467b04621db349e277dd63" "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:e0590064cd32f2baa4102fa49c80056f3886a0a89aec0589d0134ecbf0e7923e",
"sha256": "e0590064cd32f2baa4102fa49c80056f3886a0a89aec0589d0134ecbf0e7923e"
}, },
"catalina":{ "monterey": {
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.catalina.bottle.tar.gz", "cellar": "/usr/local/Cellar",
"sha256":"b651611134c18f93fdf121a4277b51b197a896a19ccb8020289b4e19e0638349" "url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:62481320613b19c6ff310bf6ed50c7d2a2253cdbf403af12ec97bccd8a97a84c",
"sha256": "62481320613b19c6ff310bf6ed50c7d2a2253cdbf403af12ec97bccd8a97a84c"
}, },
"mojave":{ "big_sur": {
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.mojave.bottle.tar.gz", "cellar": "/usr/local/Cellar",
"sha256":"9583a51fcc6f804aadbb14e18f770d4fb4973deaed6ddc4770342e62974ffbca" "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"
},
"x86_64_linux": {
"cellar": "/home/linuxbrew/.linuxbrew/Cellar",
"url": "https://ghcr.io/v2/homebrew/core/php/blobs/sha256:b934a5a4ad2d29b629f83962b57f638a654801d1ba21ba659a42da2e5afe3fae",
"sha256": "b934a5a4ad2d29b629f83962b57f638a654801d1ba21ba659a42da2e5afe3fae"
} }
} }
} }
}, },
"keg_only":false, "keg_only": false,
"bottle_disabled":false, "keg_only_reason": null,
"options":[ "options": [
], ],
"build_dependencies":[ "build_dependencies": [
"httpd", "httpd",
"pkg-config" "pkg-config"
], ],
"dependencies":[ "dependencies": [
"apr", "apr",
"apr-util", "apr-util",
"argon2", "argon2",
@@ -74,11 +87,9 @@
"freetds", "freetds",
"gd", "gd",
"gettext", "gettext",
"glib",
"gmp", "gmp",
"icu4c", "icu4c",
"krb5", "krb5",
"libffi",
"libpq", "libpq",
"libsodium", "libsodium",
"libzip", "libzip",
@@ -90,243 +101,295 @@
"tidy-html5", "tidy-html5",
"unixodbc" "unixodbc"
], ],
"recommended_dependencies":[ "test_dependencies": [
"httpd"
], ],
"optional_dependencies":[ "recommended_dependencies": [
], ],
"uses_from_macos":[ "optional_dependencies": [
],
"uses_from_macos": [
{ {
"xz":"build" "xz": "build"
}, },
"bzip2", "bzip2",
"libedit", "libedit",
"libffi",
"libxml2", "libxml2",
"libxslt", "libxslt",
"zlib" "zlib"
], ],
"requirements":[ "requirements": [
], ],
"conflicts_with":[ "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 <FilesMatch \\.php$>\n SetHandler application/x-httpd-php\n </FilesMatch>\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.0/\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 <FilesMatch \\.php$>\n SetHandler application/x-httpd-php\n </FilesMatch>\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",
"installed":[ "installed": [
{ {
"version":"8.0.2", "version": "8.1.10_1",
"used_options":[ "used_options": [
], ],
"built_as_bottle":true, "built_as_bottle": true,
"poured_from_bottle":true, "poured_from_bottle": true,
"runtime_dependencies":[ "runtime_dependencies": [
{ {
"full_name":"apr", "full_name": "apr",
"version":"1.7.0" "version": "1.7.0",
"declared_directly": true
}, },
{ {
"full_name":"openssl@1.1", "full_name": "ca-certificates",
"version":"1.1.1i" "version": "2022-07-19",
"declared_directly": false
}, },
{ {
"full_name":"apr-util", "full_name": "openssl@1.1",
"version":"1.6.1" "version": "1.1.1q",
"declared_directly": true
}, },
{ {
"full_name":"argon2", "full_name": "apr-util",
"version":"20190702" "version": "1.6.1",
"declared_directly": true
}, },
{ {
"full_name":"aspell", "full_name": "argon2",
"version":"0.60.8" "version": "20190702",
"declared_directly": true
}, },
{ {
"full_name":"autoconf", "full_name": "aspell",
"version":"2.69" "version": "0.60.8",
"declared_directly": true
}, },
{ {
"full_name":"brotli", "full_name": "m4",
"version":"1.0.9" "version": "1.4.19",
"declared_directly": false
}, },
{ {
"full_name":"gettext", "full_name": "autoconf",
"version":"0.21" "version": "2.71",
"declared_directly": true
}, },
{ {
"full_name":"libunistring", "full_name": "brotli",
"version":"0.9.10" "version": "1.0.9",
"declared_directly": false
}, },
{ {
"full_name":"libidn2", "full_name": "gettext",
"version":"2.3.0" "version": "0.21",
"declared_directly": true
}, },
{ {
"full_name":"libmetalink", "full_name": "libunistring",
"version":"0.1.3" "version": "1.0",
"declared_directly": false
}, },
{ {
"full_name":"libssh2", "full_name": "libidn2",
"version":"1.9.0" "version": "2.3.3",
"declared_directly": false
}, },
{ {
"full_name":"c-ares", "full_name": "libnghttp2",
"version":"1.17.1" "version": "1.49.0",
"declared_directly": false
}, },
{ {
"full_name":"jemalloc", "full_name": "libssh2",
"version":"5.2.1" "version": "1.10.0",
"declared_directly": false
}, },
{ {
"full_name":"libev", "full_name": "openldap",
"version":"4.33" "version": "2.6.3",
"declared_directly": true
}, },
{ {
"full_name":"nghttp2", "full_name": "rtmpdump",
"version":"1.43.0" "version": "2.4+20151223",
"declared_directly": false
}, },
{ {
"full_name":"openldap", "full_name": "lz4",
"version":"2.4.57" "version": "1.9.4",
"declared_directly": false
}, },
{ {
"full_name":"rtmpdump", "full_name": "xz",
"version":"2.4+20151223" "version": "5.2.6",
"declared_directly": false
}, },
{ {
"full_name":"zstd", "full_name": "zstd",
"version":"1.4.8" "version": "1.5.2",
"declared_directly": false
}, },
{ {
"full_name":"curl", "full_name": "curl",
"version":"7.75.0" "version": "7.85.0",
"declared_directly": true
}, },
{ {
"full_name":"libtool", "full_name": "libtool",
"version":"2.4.6" "version": "2.4.7",
"declared_directly": false
}, },
{ {
"full_name":"unixodbc", "full_name": "unixodbc",
"version":"2.3.9" "version": "2.3.11",
"declared_directly": true
}, },
{ {
"full_name":"freetds", "full_name": "freetds",
"version":"1.2.18" "version": "1.3.13",
"declared_directly": true
}, },
{ {
"full_name":"libpng", "full_name": "libpng",
"version":"1.6.37" "version": "1.6.37",
"declared_directly": false
}, },
{ {
"full_name":"freetype", "full_name": "freetype",
"version":"2.10.4" "version": "2.12.1",
"declared_directly": false
}, },
{ {
"full_name":"fontconfig", "full_name": "fontconfig",
"version":"2.13.1" "version": "2.14.0",
"declared_directly": false
}, },
{ {
"full_name":"jpeg", "full_name": "jpeg-turbo",
"version":"9d" "version": "2.1.4",
"declared_directly": false
}, },
{ {
"full_name":"libtiff", "full_name": "giflib",
"version":"4.2.0" "version": "5.2.1",
"declared_directly": false
}, },
{ {
"full_name":"webp", "full_name": "imath",
"version":"1.2.0" "version": "3.1.5",
"declared_directly": false
}, },
{ {
"full_name":"gd", "full_name": "openexr",
"version":"2.3.1" "version": "3.1.5",
"declared_directly": false
}, },
{ {
"full_name":"libffi", "full_name": "libtiff",
"version":"3.3" "version": "4.4.0",
"declared_directly": false
}, },
{ {
"full_name":"pcre", "full_name": "webp",
"version":"8.44" "version": "1.2.4",
"declared_directly": false
}, },
{ {
"full_name":"gdbm", "full_name": "jpeg-xl",
"version":"1.18.1" "version": "0.6.1",
"declared_directly": false
}, },
{ {
"full_name":"readline", "full_name": "libvmaf",
"version":"8.1" "version": "2.3.1",
"declared_directly": false
}, },
{ {
"full_name":"sqlite", "full_name": "aom",
"version":"3.34.0" "version": "3.4.0",
"declared_directly": false
}, },
{ {
"full_name":"tcl-tk", "full_name": "libavif",
"version":"8.6.11" "version": "0.10.1",
"declared_directly": false
}, },
{ {
"full_name":"xz", "full_name": "gd",
"version":"5.2.5" "version": "2.3.3",
"declared_directly": true
}, },
{ {
"full_name":"python@3.9", "full_name": "gmp",
"version":"3.9.1" "version": "6.2.1",
"declared_directly": true
}, },
{ {
"full_name":"glib", "full_name": "icu4c",
"version":"2.66.6" "version": "71.1",
"declared_directly": true
}, },
{ {
"full_name":"gmp", "full_name": "krb5",
"version":"6.2.1" "version": "1.20",
"declared_directly": true
}, },
{ {
"full_name":"icu4c", "full_name": "libpq",
"version":"67.1" "version": "14.5",
"declared_directly": true
}, },
{ {
"full_name":"krb5", "full_name": "libsodium",
"version":"1.19" "version": "1.0.18",
"declared_directly": true
}, },
{ {
"full_name":"libpq", "full_name": "libzip",
"version":"13.1" "version": "1.9.2",
"declared_directly": true
}, },
{ {
"full_name":"libsodium", "full_name": "oniguruma",
"version":"1.0.18" "version": "6.9.8",
"declared_directly": true
}, },
{ {
"full_name":"libzip", "full_name": "pcre2",
"version":"1.7.3" "version": "10.40",
"declared_directly": true
}, },
{ {
"full_name":"oniguruma", "full_name": "readline",
"version":"6.9.6" "version": "8.1.2",
"declared_directly": false
}, },
{ {
"full_name":"pcre2", "full_name": "sqlite",
"version":"10.36" "version": "3.39.2",
"declared_directly": true
}, },
{ {
"full_name":"tidy-html5", "full_name": "tidy-html5",
"version":"5.6.0" "version": "5.8.0",
"declared_directly": true
} }
], ],
"installed_as_dependency":false, "installed_as_dependency": false,
"installed_on_request":true "installed_on_request": true
} }
], ],
"linked_keg":"8.0.2", "linked_keg": "8.1.10_1",
"pinned":false, "pinned": false,
"outdated":false, "outdated": false,
"deprecated":false, "deprecated": false,
"deprecation_date":null, "deprecation_date": null,
"deprecation_reason":null, "deprecation_reason": null,
"disabled":false, "disabled": false,
"disable_date":null, "disable_date": null,
"disable_reason":null "disable_reason": null
} }
] ]

View File

@@ -14,7 +14,9 @@ class PhpEnv {
init() { init() {
self.currentInstall = ActivePhpInstallation() self.currentInstall = ActivePhpInstallation()
}
func determinePhpAlias() {
Task { Task {
let brewPhpAlias = await Shell.pipe("\(Paths.brew) info php --json").out let brewPhpAlias = await Shell.pipe("\(Paths.brew) info php --json").out
@@ -23,7 +25,7 @@ class PhpEnv {
from: brewPhpAlias.data(using: .utf8)! from: brewPhpAlias.data(using: .utf8)!
).first! ).first!
Log.info("When on your system, the `php` formula means version \(homebrewPackage.version)!") Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version)!")
} }
} }
@@ -79,14 +81,14 @@ class PhpEnv {
} }
public static func detectPhpVersions() { public static func detectPhpVersions() {
_ = Self.shared.detectPhpVersions() Task { await Self.shared.detectPhpVersions() }
} }
/** /**
Detects which versions of PHP are installed. Detects which versions of PHP are installed.
*/ */
public func detectPhpVersions() -> [String] { public func detectPhpVersions() async -> [String] {
let files = LegacyShell.pipe("ls \(Paths.optPath) | grep php@") let files = await Shell.pipe("ls \(Paths.optPath) | grep php@").out
var versionsOnly = extractPhpVersions(from: files.components(separatedBy: "\n")) var versionsOnly = extractPhpVersions(from: files.components(separatedBy: "\n"))

View File

@@ -115,7 +115,9 @@ class Startup {
// Make sure we can detect one or more PHP installations. // Make sure we can detect one or more PHP installations.
// ================================================================================= // =================================================================================
EnvironmentCheck( EnvironmentCheck(
command: { return await !Shell.pipe("ls \(Paths.optPath) | grep php").out.contains("php") }, command: {
return await !Shell.pipe("ls \(Paths.optPath) | grep php").out.contains("php")
},
name: "`ls \(Paths.optPath) | grep php` returned php result", name: "`ls \(Paths.optPath) | grep php` returned php result",
titleText: "startup.errors.php_opt.title".localized, titleText: "startup.errors.php_opt.title".localized,
subtitleText: "startup.errors.php_opt.subtitle".localized( subtitleText: "startup.errors.php_opt.subtitle".localized(

View File

@@ -42,8 +42,10 @@ class HomebrewDiagnostics {
This check only needs to be performed if the `shivammathur/php` tap is active. This check only needs to be performed if the `shivammathur/php` tap is active.
*/ */
public static func checkForCaskConflict() { public static func checkForCaskConflict() {
if hasAliasConflict() { Task {
presentAlertAboutConflict() if await hasAliasConflict() {
presentAlertAboutConflict()
}
} }
} }
@@ -79,8 +81,8 @@ class HomebrewDiagnostics {
/** /**
Check if the alias conflict as documented in `checkForCaskConflict` actually occurred. Check if the alias conflict as documented in `checkForCaskConflict` actually occurred.
*/ */
private static func hasAliasConflict() -> Bool { private static func hasAliasConflict() async -> Bool {
let tapAlias = LegacyShell.pipe("\(Paths.brew) info shivammathur/php/php --json") let tapAlias = await Shell.pipe("brew info shivammathur/php/php --json").out
if tapAlias.contains("brew tap shivammathur/php") || tapAlias.contains("Error") { if tapAlias.contains("brew tap shivammathur/php") || tapAlias.contains("Error") {
Log.info("The user does not appear to have tapped: shivammathur/php") Log.info("The user does not appear to have tapped: shivammathur/php")

View File

@@ -31,6 +31,9 @@ extension MainMenu {
When the environment is all clear and the app can run, let's go. When the environment is all clear and the app can run, let's go.
*/ */
private func onEnvironmentPass() { private func onEnvironmentPass() {
// Determine what the `php` formula is aliased to
PhpEnv.shared.determinePhpAlias()
// Determine install method // Determine install method
Log.info(HomebrewDiagnostics.customCaskInstalled Log.info(HomebrewDiagnostics.customCaskInstalled
? "The app has probably been installed via Homebrew Cask." ? "The app has probably been installed via Homebrew Cask."

View File

@@ -53,6 +53,8 @@ class Testables {
: .instant(ShellStrings.phpVersion), : .instant(ShellStrings.phpVersion),
"ls /opt/homebrew/opt | grep php" "ls /opt/homebrew/opt | grep php"
: .instant("php"), : .instant("php"),
"ls /opt/homebrew/opt | grep php@"
: .instant("php@8.1"),
"sudo /opt/homebrew/bin/brew services info nginx --json" "sudo /opt/homebrew/bin/brew services info nginx --json"
: .delayed(0.2, ShellStrings.nginxJson), : .delayed(0.2, ShellStrings.nginxJson),
"cat /private/etc/sudoers.d/brew" "cat /private/etc/sudoers.d/brew"
@@ -76,7 +78,9 @@ class Testables {
shivammathur/php shivammathur/php
"""), """),
"/opt/homebrew/bin/brew info php --json" "/opt/homebrew/bin/brew info php --json"
: .instant(ShellStrings.brewJson) : .instant(ShellStrings.brewJson),
"brew info shivammathur/php/php --json"
: .instant("Error: No available formula with the name \"shivammathur/php/php\".")
] ]
) )
} }
@@ -115,144 +119,10 @@ struct ShellStrings {
] ]
""" """
static let brewJson = """ static let brewJson: String = {
[ return try! String(contentsOf: Bundle.main.url(
{ forResource: "brew-formula",
"name":"php", withExtension: "json"
"full_name":"php", )!, encoding: .utf8)
"tap":"homebrew/core", }()
"oldname":null,
"aliases":[
"php@8.0"
],
"versioned_formulae":[
"php@7.4",
"php@7.3",
"php@7.2"
],
"desc":"General-purpose scripting language",
"license":"PHP-3.01",
"homepage":"https://www.php.net/",
"versions":{
"stable":"8.0.2",
"head":"HEAD",
"bottle":true
},
"urls":{
"stable":{
"url":"https://www.php.net/distributions/php-8.0.2.tar.xz",
"tag":null,
"revision":null
}
},
"revision":0,
"version_scheme":0,
"bottle":{
"stable":{
"rebuild":0,
"cellar":"/opt/homebrew/Cellar",
"prefix":"/opt/homebrew",
"root_url":"https://homebrew.bintray.com/bottles",
"files":{
"arm64_big_sur":{
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.arm64_big_sur.bottle.tar.gz",
"sha256":"cbefa1db73d08b9af4593a44512b8d727e43033ee8517736bae5f16315501b12"
},
"big_sur":{
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.big_sur.bottle.tar.gz",
"sha256":"6857142e12254b15da4e74c2986dd24faca57dac8d467b04621db349e277dd63"
},
"catalina":{
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.catalina.bottle.tar.gz",
"sha256":"b651611134c18f93fdf121a4277b51b197a896a19ccb8020289b4e19e0638349"
},
"mojave":{
"url":"https://homebrew.bintray.com/bottles/php-8.0.2.mojave.bottle.tar.gz",
"sha256":"9583a51fcc6f804aadbb14e18f770d4fb4973deaed6ddc4770342e62974ffbca"
}
}
}
},
"keg_only":false,
"bottle_disabled":false,
"options":[
],
"build_dependencies":[
"httpd",
"pkg-config"
],
"dependencies":[
"apr",
"apr-util",
"argon2",
"aspell",
"autoconf",
"curl",
"freetds",
"gd",
"gettext",
"glib",
"gmp",
"icu4c",
"krb5",
"libffi",
"libpq",
"libsodium",
"libzip",
"oniguruma",
"openldap",
"openssl@1.1",
"pcre2",
"sqlite",
"tidy-html5",
"unixodbc"
],
"recommended_dependencies":[
],
"optional_dependencies":[
],
"uses_from_macos":[
{
"xz":"build"
},
"bzip2",
"libedit",
"libxml2",
"libxslt",
"zlib"
],
"requirements":[
],
"conflicts_with":[
],
"installed":[
{
"version": "8.1.10_1",
"used_options": [
],
"built_as_bottle": true,
"poured_from_bottle": true,
"runtime_dependencies": [],
"installed_as_dependency": false,
"installed_on_request": true
}
],
"linked_keg":"8.0.2",
"pinned":false,
"outdated":false,
"deprecated":false,
"deprecation_date":null,
"deprecation_reason":null,
"disabled":false,
"disable_date":null,
"disable_reason":null
}
]
"""
} }