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/PhpExtensionTest.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

77 lines
2.4 KiB
Swift

//
// ExtensionParserTest.swift
// PHP Monitor
//
// Created by Nico Verbruggen on 13/02/2021.
// Copyright © 2023 Nico Verbruggen. All rights reserved.
//
import Testing
import Foundation
@Suite(.serialized)
struct PhpExtensionTest {
init () async throws {
ActiveShell.useSystem()
}
static var phpIniFileUrl: URL {
TestBundle.url(forResource: "php", withExtension: "ini")!
}
@Test func can_load_extension() throws {
let extensions = PhpExtension.from(filePath: Self.phpIniFileUrl.path)
#expect(!extensions.isEmpty)
}
@Test func extension_name_is_correct() throws {
let extensions = PhpExtension.from(filePath: Self.phpIniFileUrl.path)
let extensionNames = extensions.map { (ext) -> String in
return ext.name
}
// These 6 should be found
#expect(extensionNames.contains("xdebug"))
#expect(extensionNames.contains("imagick"))
#expect(extensionNames.contains("sodium-next"))
#expect(extensionNames.contains("opcache"))
#expect(extensionNames.contains("yaml"))
#expect(extensionNames.contains("custom"))
#expect(extensionNames.contains("fake") == false)
#expect(extensionNames.contains("nice") == false)
}
@Test func extension_status_is_correct() throws {
let extensions = PhpExtension.from(filePath: Self.phpIniFileUrl.path)
// xdebug should be enabled
#expect(extensions[0].enabled == true)
// imagick should be disabled
#expect(extensions[1].enabled == false)
}
@Test func toggle_works_as_expected() async throws {
let destination = Utility.copyToTemporaryFile(resourceName: "php", fileExtension: "ini")!
let extensions = PhpExtension.from(filePath: destination.path)
#expect(extensions.count == 6)
// Try to disable xdebug (should be detected first)!
let xdebug = extensions.first!
#expect(xdebug.name == "xdebug")
#expect(xdebug.enabled == true)
await xdebug.toggle()
#expect(xdebug.enabled == false)
// Check if the file contains the appropriate data
let file = try! String(contentsOf: destination, encoding: .utf8)
#expect(file.contains("; zend_extension=\"xdebug.so\""))
// Make sure if we load the data again, it's disabled
#expect(PhpExtension.from(filePath: destination.path).first!.enabled == false)
}
}