mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-05 18:50:08 +02:00
✅ Conditional tests
- RealWebApiTest requires api.phpmon.test to be reachable or skips - CommandTest requires php binary or skips
This commit is contained in:
19
tests/unit/Conditions/Binaries.swift
Normal file
19
tests/unit/Conditions/Binaries.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Binaries.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 16/02/2026.
|
||||
// Copyright © 2026 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class Binaries {
|
||||
static func exist(paths: [String]) -> Bool {
|
||||
for path in paths where FileManager.default.fileExists(atPath: path) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
33
tests/unit/Conditions/TestURL.swift
Normal file
33
tests/unit/Conditions/TestURL.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// URLReachable.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 16/02/2026.
|
||||
// Copyright © 2026 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class TestURL {
|
||||
static func isReachable(url: String) -> Bool {
|
||||
let process = Process()
|
||||
|
||||
process.executableURL = URL(fileURLWithPath: "/usr/bin/curl")
|
||||
process.arguments = [
|
||||
"-s", "-o", "/dev/null",
|
||||
"--max-time", "3",
|
||||
url
|
||||
]
|
||||
|
||||
process.standardOutput = Pipe()
|
||||
process.standardError = Pipe()
|
||||
|
||||
do {
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
return process.terminationStatus == 0
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user