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

👌 Fake FS: ~ and intermediate directories

This commit is contained in:
2022-11-01 16:47:45 +01:00
parent fa2d2105c5
commit 5caca85d7a
13 changed files with 192 additions and 25 deletions

View File

@ -26,15 +26,11 @@ class TestableConfigurations {
: .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1"),
"/opt/homebrew/opt/php@8.1/bin/php"
: .fake(.symlink, "/opt/homebrew/Cellar/php/8.1.10_1/bin/php"),
"/opt/homebrew/Cellar/php/8.1.10_1"
: .fake(.directory),
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php"
: .fake(.binary),
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php-config"
: .fake(.binary),
"/Users/user/.config/valet"
: .fake(.directory),
"/Users/user/.config/valet/config.json"
"~/.config/valet/config.json"
: .fake(.text, """
{
"tld": "test",

View File

@ -12,12 +12,12 @@ class TestableFileSystemTest: XCTestCase {
override class func setUp() {
ActiveFileSystem.useTestable([
"/home/user/bin": .fake(.directory),
"/home/user/bin/foo": .fake(.binary),
"/home/user/documents": .fake(.directory),
"/home/user/docs": .fake(.symlink, "/home/user/documents"),
"/home/user/documents/script.sh": .fake(.text, "echo 'cool';"),
"/home/user/documents/nice.txt": .fake(.text, "69"),
"/home/user/documents/script.sh": .fake(.text, "echo 'cool';")
"/home/user/documents/filters/filter1.txt": .fake(.text, "F1"),
"/home/user/documents/filters/filter2.txt": .fake(.text, "F2")
])
}
@ -25,7 +25,11 @@ class TestableFileSystemTest: XCTestCase {
XCTAssertTrue(FileSystem is TestableFileSystem)
}
func test_binary_directory_exists() {
func test_intermediate_directories_are_automatically_created() {
XCTAssertTrue(FileSystem.directoryExists("/"))
XCTAssertTrue(FileSystem.directoryExists("/home"))
XCTAssertTrue(FileSystem.directoryExists("/home/user"))
XCTAssertTrue(FileSystem.directoryExists("/home/user/documents"))
XCTAssertTrue(FileSystem.directoryExists("/home/user/bin"))
}
@ -53,9 +57,37 @@ class TestableFileSystemTest: XCTestCase {
withIntermediateDirectories: true
)
XCTAssertTrue(FileSystem.anyExists("/home/nico/phpmon/config"))
XCTAssertTrue(FileSystem
.anyExists("/home/nico/phpmon/config"))
XCTAssertTrue(FileSystem.directoryExists("/home/nico/phpmon/config"))
}
func test_can_create_nested_directories() throws {
try FileSystem.createDirectory(
"/home/user/thing/epic/nested/directories",
withIntermediateDirectories: true
)
XCTAssertTrue(FileSystem.directoryExists("/"))
XCTAssertTrue(FileSystem.directoryExists("/home"))
XCTAssertTrue(FileSystem.directoryExists("/home/user"))
XCTAssertTrue(FileSystem.directoryExists("/home/user/thing"))
XCTAssertTrue(FileSystem.directoryExists("/home/user/thing/epic/nested"))
XCTAssertTrue(FileSystem.directoryExists("/home/user/thing/epic/nested/directories"))
}
func test_can_list_directory_contents() throws {
let contents = try! FileSystem.getShallowContentsOfDirectory("/home/user/documents")
XCTAssertEqual(
contents.sorted(),
[
"script.sh",
"nice.txt",
"filters"
].sorted()
)
}
// TODO: Implement and test the remove() and move() methods and reorganize method order
}