1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-11-05 04:20:06 +01:00
Files
app/tests/unit/SwiftTestMigrated/Parsers/PhpConfigurationFileTest.swift
Nico Verbruggen 85b12d1aec ♻️ Prevent unit tests from running concurrently
The way the testing classes are built with the singletons currently
prevents various test structs from being run at the same time.

I've adjusted the tests in the PHP Monitor EAP test configuration so
that they are not executed concurrently. This does slow down the test
suite but prevents odd crashes from individual tests interfering with
other tests.

It's not an ideal solution and I would like to address this in the
future, but I suspect this will be rather cumbersome. Since the app
does not actually suffer from this particular issue, this is something
worth investigating later.
2025-09-30 16:14:17 +02:00

81 lines
2.5 KiB
Swift

//
// PhpConfigurationFileTest.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 04/05/2022.
// Copyright © 2023 Nico Verbruggen. All rights reserved.
//
import Testing
import Foundation
@Suite(.serialized)
class PhpConfigurationFileTest {
static var phpIniFileUrl: URL {
return TestBundle.url(forResource: "php", withExtension: "ini")!
}
@Test func can_load_extension() throws {
ActiveFileSystem.useSystem()
let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)
#expect(iniFile != nil)
#expect(!iniFile!.extensions.isEmpty)
}
@Test func can_check_key_existence() throws {
print(Self.phpIniFileUrl.path)
let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)!
#expect(iniFile.has(key: "error_reporting"))
#expect(iniFile.has(key: "display_errors"))
#expect(false == iniFile.has(key: "my_unknown_key"))
}
@Test func can_check_key_value() throws {
let iniFile = PhpConfigurationFile.from(filePath: Self.phpIniFileUrl.path)!
#expect(iniFile.get(for: "error_reporting") != nil)
#expect(iniFile.get(for: "error_reporting") == "E_ALL")
#expect(iniFile.get(for: "display_errors") != nil)
#expect(iniFile.get(for: "display_errors") == "On")
}
@Test func 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
#expect(configurationFile.get(for: "error_reporting") == "E_ALL")
// 1. Change the value
try! configurationFile.replace(
key: "error_reporting",
value: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
)
#expect(
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"
)
#expect(configurationFile.get(for: "error_reporting") == "error_reporting")
// 3. Verify subsequent saves weren't broken
try! configurationFile.replace(
key: "error_reporting",
value: "E_ALL"
)
#expect(configurationFile.get(for: "error_reporting") == "E_ALL")
}
}