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

👌 Add feature test for InternalSwitcher

This commit is contained in:
2022-11-07 20:42:52 +01:00
parent a21d928a6c
commit bc739e1982
5 changed files with 124 additions and 16 deletions

View File

@ -1,11 +0,0 @@
//
// Feature_Tests.swift
// Feature Tests
//
// Created by Nico Verbruggen on 14/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
final class Feature_Tests: XCTestCase {}

View File

@ -0,0 +1,49 @@
//
// FeatureTestCase.swift
// Feature Tests
//
// Created by Nico Verbruggen on 07/11/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
class FeatureTestCase: XCTestCase {
var fakeFileSystem: TestableFileSystem {
let fs = ActiveFileSystem.shared
if fs is TestableFileSystem {
return fs as! TestableFileSystem
}
fatalError("The active filesystem is not a TestableFileSystem. Please use `ActiveFileSystem` to use the fake filesystem.")
}
public func assertFileSystemHas(
_ path: String,
file: StaticString = #filePath,
line: UInt = #line
) {
XCTAssertTrue(fakeFileSystem.files.keys.contains(path), file: file, line: line)
}
public func assertFileSystemDoesNotHave(
_ path: String,
file: StaticString = #filePath,
line: UInt = #line
) {
XCTAssertFalse(fakeFileSystem.files.keys.contains(path), file: file, line: line)
}
public func assertFileHasContents(
_ path: String,
contents: String,
file: StaticString = #filePath,
line: UInt = #line
) {
XCTAssertEqual(contents, fakeFileSystem.files[path]?.content, file: file, line: line)
}
}

View File

@ -0,0 +1,55 @@
//
// Feature_Tests.swift
// Feature Tests
//
// Created by Nico Verbruggen on 14/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
final class InternalSwitcherTest: FeatureTestCase {
public func testDefaultPhpFpmPoolRequiresDisabling() async {
ActiveFileSystem.useTestable([
"/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf": .fake(.text)
])
assertFileSystemHas("/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf")
XCTAssertTrue(InternalSwitcher().requiresDisablingOfDefaultPhpFpmPool("8.1"))
}
public func testDefaultPhpFpmPoolIsMoved() async {
ActiveFileSystem.useTestable([
"/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf": .fake(.text)
])
await InternalSwitcher().disableDefaultPhpFpmPool("8.1")
assertFileSystemHas("/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf.disabled-by-phpmon")
assertFileSystemDoesNotHave("/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf")
}
public func testExistingDisabledByPhpMonFileIsRemoved() async {
ActiveFileSystem.useTestable([
"/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf": .fake(.text, "system generated"),
"/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf.disabled-by-phpmon": .fake(.text, "phpmon generated")
])
assertFileHasContents(
"/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf.disabled-by-phpmon",
contents: "phpmon generated"
)
await InternalSwitcher().disableDefaultPhpFpmPool("8.1")
assertFileSystemHas("/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf.disabled-by-phpmon")
assertFileSystemDoesNotHave("/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf")
assertFileHasContents(
"/opt/homebrew/etc/php/8.1/php-fpm.d/www.conf.disabled-by-phpmon",
contents: "system generated"
)
}
}