mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 12:00:09 +02:00
✨ Allow reading of configuration files
This commit is contained in:
@ -22,6 +22,24 @@ class PhpConfigurationTest: XCTestCase {
|
|||||||
XCTAssertGreaterThan(iniFile.extensions.count, 0)
|
XCTAssertGreaterThan(iniFile.extensions.count, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCanCheckKeyExistence() throws {
|
||||||
|
let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)!
|
||||||
|
|
||||||
|
XCTAssertTrue(iniFile.has(key: "error_reporting"))
|
||||||
|
XCTAssertTrue(iniFile.has(key: "display_errors"))
|
||||||
|
XCTAssertFalse(iniFile.has(key: "my_unknown_key"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCanCheckKeyValue() throws {
|
||||||
|
let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)!
|
||||||
|
|
||||||
|
XCTAssertNotNil(iniFile.get(for: "error_reporting"))
|
||||||
|
XCTAssert(iniFile.get(for: "error_reporting") == "E_ALL")
|
||||||
|
|
||||||
|
XCTAssertNotNil(iniFile.get(for: "display_errors"))
|
||||||
|
XCTAssert(iniFile.get(for: "display_errors") == "On")
|
||||||
|
}
|
||||||
|
|
||||||
func testCanSwapConfigurationValue() throws {
|
func testCanSwapConfigurationValue() throws {
|
||||||
let destination = Utility.copyToTemporaryFile(resourceName: "php", fileExtension: "ini")!
|
let destination = Utility.copyToTemporaryFile(resourceName: "php", fileExtension: "ini")!
|
||||||
|
|
||||||
|
@ -53,12 +53,19 @@ class PhpConfigurationFile: CreatedFromFile {
|
|||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
|
|
||||||
public func has(key: String) {
|
public func has(key: String) -> Bool {
|
||||||
// TODO
|
return self.content.contains { (_: String, section: Section) in
|
||||||
|
return section.keys.contains(key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func value(for key: String) {
|
public func get(for key: String) -> String? {
|
||||||
// TODO
|
for (_, section) in self.content {
|
||||||
|
if section.keys.contains(key) {
|
||||||
|
return section[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public func replace(key: String, value: String) {
|
public func replace(key: String, value: String) {
|
||||||
|
Reference in New Issue
Block a user