mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-03-29 16:10:08 +02:00
♻️ WIP: Change some tests to Swift Testing, add TestBundle
This commit is contained in:
50
tests/Shared/TestBundle.swift
Normal file
50
tests/Shared/TestBundle.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// BundleHelper.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 25/08/2025.
|
||||
// Copyright © 2025 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
This file is used to access bundle resources via test structs
|
||||
that cannot access the bundle via the previous class syntax.
|
||||
|
||||
After converting a test to Swift Testing, this is no longer possible:
|
||||
|
||||
```swift
|
||||
class MyTest: XCTestCase {
|
||||
static var configurationFileUrl: URL {
|
||||
return Bundle(for: Self.self).url(
|
||||
forResource: "valet-config",
|
||||
withExtension: "json"
|
||||
)!
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Normally, we would be able to access the bundle via the class
|
||||
itself, but we'd prefer _not_ to make this accessible to other
|
||||
classes. Thankfully, this is where `fileprivate` shines.
|
||||
|
||||
The bundle is now accessed via `TestBundleClass`, which is not
|
||||
accessible outside the scope of this file. `TestBundle` as a
|
||||
global variable, though, is!
|
||||
|
||||
Usage:
|
||||
|
||||
```swift
|
||||
return TestBundle.url(
|
||||
forResource: "valet-config",
|
||||
withExtension: "json"
|
||||
)!
|
||||
```
|
||||
*/
|
||||
|
||||
fileprivate class TestBundleClass {}
|
||||
|
||||
public var TestBundle: Bundle {
|
||||
return Bundle(for: TestBundleClass.self)
|
||||
}
|
||||
@@ -6,21 +6,23 @@
|
||||
// Copyright © 2023 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
class CommandTest: XCTestCase {
|
||||
@Suite("Commands")
|
||||
struct CommandTest {
|
||||
|
||||
func test_determine_php_version() {
|
||||
@Test
|
||||
func determinePhpVersion() {
|
||||
let version = Command.execute(
|
||||
path: Paths.php,
|
||||
arguments: ["-v"],
|
||||
trimNewlines: false
|
||||
)
|
||||
|
||||
XCTAssert(version.contains("(cli)"))
|
||||
XCTAssert(version.contains("NTS"))
|
||||
XCTAssert(version.contains("built"))
|
||||
XCTAssert(version.contains("Zend"))
|
||||
#expect(version.contains("(cli)"))
|
||||
#expect(version.contains("NTS"))
|
||||
#expect(version.contains("built"))
|
||||
#expect(version.contains("Zend"))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
import Testing
|
||||
|
||||
@Suite("Integration")
|
||||
struct PackagistTest {
|
||||
@Test func packagistRetrieval() async {
|
||||
let packageToCheck = "laravel/valet"
|
||||
@@ -6,18 +6,20 @@
|
||||
// Copyright © 2023 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
class ValetConfigurationTest: XCTestCase {
|
||||
import Testing
|
||||
import Foundation
|
||||
|
||||
@Suite("Parsers")
|
||||
struct ValetConfigurationTest {
|
||||
static var jsonConfigFileUrl: URL {
|
||||
return Bundle(for: Self.self).url(
|
||||
return TestBundle.url(
|
||||
forResource: "valet-config",
|
||||
withExtension: "json"
|
||||
)!
|
||||
}
|
||||
|
||||
func test_can_load_config_file() throws {
|
||||
@Test("Can load config file")
|
||||
func can_load_config_file() throws {
|
||||
let json = try? String(
|
||||
contentsOf: Self.jsonConfigFileUrl,
|
||||
encoding: .utf8
|
||||
@@ -27,13 +29,13 @@ class ValetConfigurationTest: XCTestCase {
|
||||
from: json!.data(using: .utf8)!
|
||||
)
|
||||
|
||||
XCTAssertEqual(config.tld, "test")
|
||||
XCTAssertEqual(config.paths, [
|
||||
#expect(config.tld == "test")
|
||||
#expect(config.paths == [
|
||||
"/Users/username/.config/valet/Sites",
|
||||
"/Users/username/Sites"
|
||||
])
|
||||
XCTAssertEqual(config.defaultSite, "/Users/username/default-site")
|
||||
XCTAssertEqual(config.loopback, "127.0.0.1")
|
||||
#expect(config.defaultSite == "/Users/username/default-site")
|
||||
#expect(config.loopback == "127.0.0.1")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user