mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 FileSystem changes, rework and testing
This commit is contained in:
@ -14,6 +14,8 @@ class TestableConfigurations {
|
||||
return TestableConfiguration(
|
||||
architecture: "arm64",
|
||||
filesystem: [
|
||||
"/usr/local/bin/"
|
||||
: .fake(.directory, readOnly: true),
|
||||
"/opt/homebrew/bin/brew"
|
||||
: .fake(.binary),
|
||||
"/opt/homebrew/bin/php"
|
||||
@ -30,10 +32,21 @@ class TestableConfigurations {
|
||||
: .fake(.binary),
|
||||
"/opt/homebrew/Cellar/php/8.1.10_1/bin/php-config"
|
||||
: .fake(.binary),
|
||||
"~/.config/valet"
|
||||
"/Users/user/.config/valet"
|
||||
: .fake(.directory),
|
||||
"/Users/user/.config/valet/config.json"
|
||||
: .fake(.text, """
|
||||
{
|
||||
"tld": "test",
|
||||
"paths": [
|
||||
"/Users/user/.config/valet/Sites",
|
||||
"/Users/user/Sites"
|
||||
],
|
||||
"loopback": "127.0.0.1"
|
||||
}
|
||||
"""),
|
||||
"/opt/homebrew/etc/php/8.1/php-fpm.d/valet-fpm.conf"
|
||||
: .fake(.text)
|
||||
: .fake(.text),
|
||||
],
|
||||
shellOutput: [
|
||||
"sysctl -n sysctl.proc_translated"
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Utility.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 14/02/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// CommandTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 13/02/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// BrewJsonParserTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 14/02/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// NginxConfigurationTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 29/11/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// ExtensionParserTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 13/02/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// ValetConfigParserTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 29/11/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
61
tests/unit/Testables/Filesystem/TestableFileSystemTest.swift
Normal file
61
tests/unit/Testables/Filesystem/TestableFileSystemTest.swift
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// TestableFileSystemTest.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 01/11/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
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/nice.txt": .fake(.text, "69"),
|
||||
"/home/user/documents/script.sh": .fake(.text, "echo 'cool';")
|
||||
])
|
||||
}
|
||||
|
||||
func test_testable_fs_is_in_use() {
|
||||
XCTAssertTrue(FileSystem is TestableFileSystem)
|
||||
}
|
||||
|
||||
func test_binary_directory_exists() {
|
||||
XCTAssertTrue(FileSystem.directoryExists("/home/user/bin"))
|
||||
}
|
||||
|
||||
func test_binary_directory_is_writable() {
|
||||
XCTAssertTrue(FileSystem.isWriteableFile("/home/user/bin"))
|
||||
}
|
||||
|
||||
func test_binary_exists() {
|
||||
XCTAssertTrue(FileSystem.isExecutableFile("/home/user/bin/foo"))
|
||||
}
|
||||
|
||||
func test_can_write_text_to_executable() throws {
|
||||
try! FileSystem.writeAtomicallyToFile("/home/user/bin/bar", content: "bar bar bar!")
|
||||
|
||||
XCTAssertFalse(FileSystem.isExecutableFile("/home/user/bin/bar"))
|
||||
|
||||
try! FileSystem.makeExecutable("/home/user/bin/bar")
|
||||
|
||||
XCTAssertTrue(FileSystem.isExecutableFile("/home/user/bin/bar"))
|
||||
}
|
||||
|
||||
func test_can_create_directory() throws {
|
||||
try! FileSystem.createDirectory(
|
||||
"/home/nico/phpmon/config",
|
||||
withIntermediateDirectories: true
|
||||
)
|
||||
|
||||
XCTAssertTrue(FileSystem.anyExists("/home/nico/phpmon/config"))
|
||||
XCTAssertTrue(FileSystem.directoryExists("/home/nico/phpmon/config"))
|
||||
}
|
||||
|
||||
// TODO: Implement and test the remove() and move() methods and reorganize method order
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// SystemShellTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 28/09/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// ShellTest.swift
|
||||
// phpmon-tests
|
||||
// TestableShellTest.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 20/09/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
import XCTest
|
||||
|
||||
class FakeShellTest: XCTestCase {
|
||||
class TestableShellTest: XCTestCase {
|
||||
func test_fake_shell_output_can_be_declared() async {
|
||||
let greeting = BatchFakeShellOutput(items: [
|
||||
.instant("Hello world\n"),
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// AppUpdaterCheckTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 10/05/2022.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// PhpVersionDetectionTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 01/04/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// ValetTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 29/11/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// VersionExtractorTest.swift
|
||||
// phpmon-tests
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 16/12/2021.
|
||||
// Copyright © 2022 Nico Verbruggen. All rights reserved.
|
||||
|
Reference in New Issue
Block a user