mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-12-21 03:10:06 +01:00
- RealShell is not reloaded during runtime (bugfix?) - Container variables are now private(set) - Initialization now also sets `webApi` property (new) - It is only possible to run `bind` on a `Container` once now (previously known as `prepare`) - Preparation for upcoming WebApi to replace `curl` command (for checking for updates)
42 lines
980 B
Swift
42 lines
980 B
Swift
//
|
|
// TestableWebApi.swift
|
|
// PHP Monitor
|
|
//
|
|
// Created by Nico Verbruggen on 29/09/2025.
|
|
// Copyright © 2025 Nico Verbruggen. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class TestableWebApi: WebApiProtocol {
|
|
private var fakeResponses: [URL: FakeWebApiResponse] = [:]
|
|
|
|
init(responses: [URL: FakeWebApiResponse]) {
|
|
self.fakeResponses = responses
|
|
}
|
|
|
|
public func hasResponse(for url: URL) -> Bool {
|
|
return fakeResponses.keys.contains(url)
|
|
}
|
|
|
|
public func getResponse(for url: URL) -> FakeWebApiResponse {
|
|
return fakeResponses[url]!
|
|
}
|
|
}
|
|
|
|
struct FakeWebApiResponse {
|
|
let statusCode: Int
|
|
let headers: [String: String]
|
|
let data: Data?
|
|
|
|
init(statusCode: Int, headers: [String: String], text: String) {
|
|
self.statusCode = statusCode
|
|
self.headers = headers
|
|
self.data = text.data(using: .utf8)
|
|
}
|
|
|
|
var text: String {
|
|
return String(data: self.data!, encoding: .utf8) ?? ""
|
|
}
|
|
}
|