1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

🏗️ WIP: Reading of bitsize config entries

This commit is contained in:
2023-09-04 18:39:32 +02:00
parent 51c100f6fe
commit 7977a4e177
9 changed files with 226 additions and 59 deletions

View File

@@ -0,0 +1,42 @@
//
// BytePhpPreferenceTest.swift
// Unit Tests
//
// Created by Nico Verbruggen on 04/09/2023.
// Copyright © 2023 Nico Verbruggen. All rights reserved.
//
import XCTest
class BytePhpPreferenceTest: XCTestCase {
func test_can_extract_memory_value() throws {
let pref = BytePhpPreference(key: "memory_limit")
XCTAssertEqual(pref.internalValue, "512M")
XCTAssertEqual(pref.unit, .megabyte)
XCTAssertEqual(pref.value, 512)
}
func test_can_parse_all_kinds_of_values() throws {
var (unit, value) = BytePhpPreference.readFrom(internalValue: "1G")!
XCTAssertEqual(unit, .gigabyte)
XCTAssertEqual(value, 1)
(unit, value) = BytePhpPreference.readFrom(internalValue: "256M")!
XCTAssertEqual(unit, .megabyte)
XCTAssertEqual(value, 256)
(unit, value) = BytePhpPreference.readFrom(internalValue: "512K")!
XCTAssertEqual(unit, .kilobyte)
XCTAssertEqual(value, 512)
(unit, value) = BytePhpPreference.readFrom(internalValue: "1024")!
XCTAssertEqual(unit, .kilobyte)
XCTAssertEqual(value, 1024)
(unit, value) = BytePhpPreference.readFrom(internalValue: "-1")!
XCTAssertEqual(unit, .kilobyte)
XCTAssertEqual(value, -1)
}
}

View File

@@ -0,0 +1,84 @@
//
// PhpConfigurationFileTest.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 04/05/2022.
// Copyright © 2023 Nico Verbruggen. All rights reserved.
//
import XCTest
class PhpConfigurationFileTest: XCTestCase {
static var phpIniFileUrl: URL {
return Bundle(for: Self.self).url(forResource: "php", withExtension: "ini")!
}
func test_can_load_extension() throws {
let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)!
XCTAssertNotNil(iniFile)
XCTAssertGreaterThan(iniFile.extensions.count, 0)
}
func test_can_check_key_existence() 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 test_can_check_key_value() 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 test_can_customize_configuration_value() throws {
let destination = Utility
.copyToTemporaryFile(resourceName: "php", fileExtension: "ini")!
let configurationFile = PhpConfigurationFile
.from(filePath: destination.path)!
// 0. Verify the original value
XCTAssertEqual(configurationFile.get(for: "error_reporting"), "E_ALL")
// 1. Change the value
try! configurationFile.replace(
key: "error_reporting",
value: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
)
XCTAssertEqual(
configurationFile.get(for: "error_reporting"),
"E_ALL & ~E_DEPRECATED & ~E_STRICT"
)
// 2. Ensure that same key and value doesn't break subsequent saves
try! configurationFile.replace(
key: "error_reporting",
value: "error_reporting"
)
XCTAssertEqual(
configurationFile.get(for: "error_reporting"),
"error_reporting"
)
// 3. Verify subsequent saves weren't broken
try! configurationFile.replace(
key: "error_reporting",
value: "E_ALL"
)
XCTAssertEqual(
configurationFile.get(for: "error_reporting"),
"E_ALL"
)
}
}