mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-27 06:20:08 +01:00
♻️ Add optional command tracking for container
- This allows existing unit tests to work - But we can also test command tracking in the future
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
//
|
||||
|
||||
extension Container {
|
||||
public static func real(minimal: Bool = false) -> Container {
|
||||
public static func real(minimal: Bool = false, commandTracking: Bool = true) -> Container {
|
||||
let container = Container()
|
||||
container.bind(coreOnly: minimal)
|
||||
container.bind(coreOnly: minimal, commandTracking: commandTracking)
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,10 @@ class Container: @unchecked Sendable {
|
||||
/// - Parameter coreOnly: Only binds `shell`, `filesystem`, `command`, `paths` and `webApi`.
|
||||
/// Use this to prevent slowing down tests for a minimal container.
|
||||
///
|
||||
public func bind(coreOnly: Bool = false) {
|
||||
/// - Parameter commandTracking: When enabled, connects decorated RealShell and RealCommand.
|
||||
/// Use this if you want to disable tracking (shell) command statuses, since it's on by default.
|
||||
///
|
||||
public func bind(coreOnly: Bool = false, commandTracking: Bool = true) {
|
||||
if self.bound {
|
||||
fatalError("You cannot call `bind` on a Container more than once.")
|
||||
}
|
||||
@@ -69,8 +72,19 @@ class Container: @unchecked Sendable {
|
||||
self.filesystem = RealFileSystem(container: self)
|
||||
self.paths = Paths(container: self)
|
||||
self.commandTracker = CommandTracker()
|
||||
self.shell = TrackedShell(shell: RealShell(binPath: paths.binPath), commandTracker: commandTracker)
|
||||
self.command = TrackedCommand(command: RealCommand(), commandTracker: commandTracker)
|
||||
|
||||
let baseShellHandler = RealShell(binPath: paths.binPath)
|
||||
let baseCommandHandler = RealCommand()
|
||||
|
||||
// Depending on whether we need command tracking wired up, we will use different real handlers
|
||||
if commandTracking {
|
||||
self.shell = TrackedShell(shell: baseShellHandler, commandTracker: commandTracker)
|
||||
self.command = TrackedCommand(command: baseCommandHandler, commandTracker: commandTracker)
|
||||
} else {
|
||||
self.shell = baseShellHandler
|
||||
self.command = baseCommandHandler
|
||||
}
|
||||
|
||||
self.webApi = RealWebApi(container: self)
|
||||
|
||||
if coreOnly {
|
||||
|
||||
@@ -14,7 +14,7 @@ struct RealShellTest {
|
||||
|
||||
init() async throws {
|
||||
// Reset to the default shell
|
||||
container = Container.real(minimal: true)
|
||||
container = Container.real(minimal: true, commandTracking: false)
|
||||
}
|
||||
|
||||
@Test func system_shell_is_default() async {
|
||||
|
||||
Reference in New Issue
Block a user