mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Read configuration from JSON file
This allows us to alter the configuration prior to launching the app, which allows for additional flexibility during testing.
This commit is contained in:
23
tests/Shared/XCPMApplication.swift
Normal file
23
tests/Shared/XCPMApplication.swift
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// XCPMApplication.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 16/10/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class XCPMApplication: XCUIApplication {
|
||||
public func withConfiguration(_ configuration: TestableConfiguration) {
|
||||
let path = persistTestable(configuration)
|
||||
self.launchArguments = ["--configuration:\(path)"]
|
||||
}
|
||||
|
||||
private func persistTestable(_ configuration: TestableConfiguration) -> String {
|
||||
let tempDirectoryURL = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
let targetURL = tempDirectoryURL.appendingPathComponent("\(UUID().uuidString).json")
|
||||
try! configuration.toJson().write(toFile: targetURL.path, atomically: true, encoding: .utf8)
|
||||
return targetURL.path
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user