From ed3622cc4eb11e09f132b4bd4512a83b76470971 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 6 Oct 2022 23:00:21 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Fix=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Parsers/HomebrewPackageTest.swift | 17 +++++++------ phpmon-tests/Parsers/PhpExtensionTest.swift | 4 +-- .../Versions/AppUpdaterCheckTest.swift | 4 +-- .../Versions/PhpVersionDetectionTest.swift | 4 +-- .../Versions/ValetVersionExtractorTest.swift | 4 +-- phpmon/Domain/Menu/MainMenu+Actions.swift | 25 ++++++++++--------- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/phpmon-tests/Parsers/HomebrewPackageTest.swift b/phpmon-tests/Parsers/HomebrewPackageTest.swift index 5bd30a2..65b55c8 100644 --- a/phpmon-tests/Parsers/HomebrewPackageTest.swift +++ b/phpmon-tests/Parsers/HomebrewPackageTest.swift @@ -53,13 +53,14 @@ class HomebrewPackageTest: XCTestCase { /// and requires the Valet services to be installed: php, nginx and dnsmasq. /// If this test fails, there is an issue with your Homebrew installation /// or the JSON API of the Homebrew output may have changed. - func testCanParseServicesJsonFromCliOutput() throws { + func testCanParseServicesJsonFromCliOutput() async throws { + ActiveShell.useSystem() + let services = try! JSONDecoder().decode( [HomebrewService].self, - from: LegacyShell.pipe( - "sudo \(Paths.brew) services info --all --json", - requiresPath: true - ).data(using: .utf8)! + from: await Shell.pipe( + "sudo \(Paths.brew) services info --all --json" + ).out.data(using: .utf8)! ).filter({ service in return ["php", "nginx", "dnsmasq"].contains(service.name) }) @@ -74,10 +75,12 @@ class HomebrewPackageTest: XCTestCase { /// and requires the `php` formula to be installed. /// If this test fails, there is an issue with your Homebrew installation /// or the JSON API of the Homebrew output may have changed. - func testCanLoadExtensionJsonFromCliOutput() throws { + func testCanLoadExtensionJsonFromCliOutput() async throws { + ActiveShell.useSystem() + let package = try! JSONDecoder().decode( [HomebrewPackage].self, - from: LegacyShell.pipe("\(Paths.brew) info php --json", requiresPath: true).data(using: .utf8)! + from: await Shell.pipe("\(Paths.brew) info php --json").out.data(using: .utf8)! ).first! XCTAssertTrue(package.name == "php") diff --git a/phpmon-tests/Parsers/PhpExtensionTest.swift b/phpmon-tests/Parsers/PhpExtensionTest.swift index 0e38c5e..5fc8c49 100644 --- a/phpmon-tests/Parsers/PhpExtensionTest.swift +++ b/phpmon-tests/Parsers/PhpExtensionTest.swift @@ -49,7 +49,7 @@ class PhpExtensionTest: XCTestCase { XCTAssertEqual(extensions[1].enabled, false) } - func testToggleWorksAsExpected() throws { + func testToggleWorksAsExpected() async throws { let destination = Utility.copyToTemporaryFile(resourceName: "php", fileExtension: "ini")! let extensions = PhpExtension.from(filePath: destination.path) XCTAssertEqual(extensions.count, 6) @@ -58,7 +58,7 @@ class PhpExtensionTest: XCTestCase { let xdebug = extensions.first! XCTAssertTrue(xdebug.name == "xdebug") XCTAssertEqual(xdebug.enabled, true) - xdebug.toggle() + await xdebug.toggle() XCTAssertEqual(xdebug.enabled, false) // Check if the file contains the appropriate data diff --git a/phpmon-tests/Versions/AppUpdaterCheckTest.swift b/phpmon-tests/Versions/AppUpdaterCheckTest.swift index a108ac5..04faaae 100644 --- a/phpmon-tests/Versions/AppUpdaterCheckTest.swift +++ b/phpmon-tests/Versions/AppUpdaterCheckTest.swift @@ -10,8 +10,8 @@ import XCTest class AppUpdaterCheckTest: XCTestCase { - func testCanRetrieveVersionFromCask() { - let caskVersion = AppUpdateChecker.retrieveVersionFromCask() + func testCanRetrieveVersionFromCask() async { + let caskVersion = await AppUpdateChecker.retrieveVersionFromCask() let version = VersionExtractor.from(caskVersion) diff --git a/phpmon-tests/Versions/PhpVersionDetectionTest.swift b/phpmon-tests/Versions/PhpVersionDetectionTest.swift index ac92e33..e25b2b5 100644 --- a/phpmon-tests/Versions/PhpVersionDetectionTest.swift +++ b/phpmon-tests/Versions/PhpVersionDetectionTest.swift @@ -10,8 +10,8 @@ import XCTest class PhpVersionDetectionTest: XCTestCase { - func testCanDetectValidPhpVersions() throws { - let outcome = PhpEnv.shared.extractPhpVersions(from: [ + func testCanDetectValidPhpVersions() async throws { + let outcome = await PhpEnv.shared.extractPhpVersions(from: [ "", // empty lines should be omitted "php@8.0", "php@8.0", // should only be detected once diff --git a/phpmon-tests/Versions/ValetVersionExtractorTest.swift b/phpmon-tests/Versions/ValetVersionExtractorTest.swift index aab593c..89c6a63 100644 --- a/phpmon-tests/Versions/ValetVersionExtractorTest.swift +++ b/phpmon-tests/Versions/ValetVersionExtractorTest.swift @@ -10,8 +10,8 @@ import XCTest class ValetVersionExtractorTest: XCTestCase { - func testDetermineValetVersion() { - let version = valet("--version", sudo: false) + func testDetermineValetVersion() async { + let version = await valet("--version", sudo: false) XCTAssert(version.contains("Laravel Valet 2") || version.contains("Laravel Valet 3")) } diff --git a/phpmon/Domain/Menu/MainMenu+Actions.swift b/phpmon/Domain/Menu/MainMenu+Actions.swift index 0e66a57..e4e04f4 100644 --- a/phpmon/Domain/Menu/MainMenu+Actions.swift +++ b/phpmon/Domain/Menu/MainMenu+Actions.swift @@ -47,6 +47,19 @@ extension MainMenu { } } + @objc func restartNginx() { + Task { // Simple restart service + await Actions.restartNginx() + } + } + + @objc func restartDnsMasq() { + Task { // Simple restart service + await Actions.restartDnsMasq() + } + } + + @MainActor @objc func restartValetServices() { Task { // Restart services and show notification await Actions.restartDnsMasq() @@ -73,18 +86,6 @@ extension MainMenu { } } - @objc func restartNginx() { - Task { - await Actions.restartNginx() - } - } - - @objc func restartDnsMasq() { - Task { - await Actions.restartDnsMasq() - } - } - @objc func disableAllXdebugModes() { guard let file = PhpEnv.shared.getConfigFile(forKey: "xdebug.mode") else { Log.info("xdebug.mode could not be found in any .ini file, aborting.")