diff --git a/phpmon-tests/BrewJsonParserTest.swift b/phpmon-tests/BrewJsonParserTest.swift index 7db5889..1e27816 100644 --- a/phpmon-tests/BrewJsonParserTest.swift +++ b/phpmon-tests/BrewJsonParserTest.swift @@ -9,12 +9,15 @@ import XCTest class BrewJsonParserTest: XCTestCase { + + // - MARK: SYNTHETIC TESTS static var jsonBrewFile: URL { - return Bundle(for: Self.self).url(forResource: "brew", withExtension: "json")! + return Bundle(for: Self.self) + .url(forResource: "brew", withExtension: "json")! } - func testCanLoadExtension() throws { + func testCanLoadExtensionJson() throws { let json = try! String(contentsOf: Self.jsonBrewFile, encoding: .utf8) let package = try! JSONDecoder().decode( [HomebrewPackage].self, from: json.data(using: .utf8)! @@ -29,7 +32,8 @@ class BrewJsonParserTest: XCTestCase { } static var jsonBrewServicesFile: URL { - return Bundle(for: Self.self).url(forResource: "brew-services", withExtension: "json")! + return Bundle(for: Self.self) + .url(forResource: "brew-services", withExtension: "json")! } func testCanParseServicesJson() throws { @@ -42,5 +46,37 @@ class BrewJsonParserTest: XCTestCase { XCTAssertEqual(services.first?.name, "dnsmasq") XCTAssertEqual(services.first?.service_name, "homebrew.mxcl.dnsmasq") } + + // - MARK: LIVE TESTS + /// This test requires that you have a valid Homebrew installation set up, + /// and requires the Valet services to be installed: php, nginx and dnsmasq. + /// Otherwise, this test won't fail. 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 { + let services = try! JSONDecoder().decode( + [HomebrewService].self, + from: Shell.pipe( + "sudo \(Paths.brew) services info --all --json", + requiresPath: true + ).data(using: .utf8)! + ) + + XCTAssertTrue(services.contains(where: {$0.name == "php"} )) + XCTAssertTrue(services.contains(where: {$0.name == "nginx"} )) + XCTAssertTrue(services.contains(where: {$0.name == "dnsmasq"} )) + } + + /// This test requires that you have a valid Homebrew installation set up, + /// and requires the Valet services to be installed: php, nginx and dnsmasq. + /// Otherwise, this test won't fail. 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 { + let package = try! JSONDecoder().decode( + [HomebrewPackage].self, + from: Shell.pipe("\(Paths.brew) info php --json", requiresPath: true).data(using: .utf8)! + ).first! + + XCTAssertTrue(package.name == "php") + } }