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

Test synchronous shell output

This commit is contained in:
2023-11-26 21:48:40 +01:00
parent e8306289ce
commit a7d5950aa0
5 changed files with 66 additions and 11 deletions

View File

@ -23,6 +23,14 @@ class RealShellTest: XCTestCase {
XCTAssertTrue(output.out.contains("Copyright (c) The PHP Group"))
}
func test_system_shell_can_be_used_synchronously() {
XCTAssertTrue(Shell is RealShell)
let output = Shell.sync("php -v")
XCTAssertTrue(output.out.contains("Copyright (c) The PHP Group"))
}
func test_system_shell_has_path() {
let systemShell = Shell as! RealShell

View File

@ -30,6 +30,35 @@ class TestableShellTest: XCTestCase {
XCTAssertEqual("Hello world\nGoodbye world", output.out)
}
func test_fake_shell_synchronous_output() {
let greeting = BatchFakeShellOutput(items: [
.instant("Hello world\n"),
.delayed(0.2, "Goodbye world")
])
let output = greeting.syncOutput()
XCTAssertEqual("Hello world\nGoodbye world", output.out)
}
func test_fake_shell_usage() {
let expectedOutput = """
PHP 8.3.0 (cli) (built: Nov 21 2023 14:40:35) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
with Xdebug v3.2.2, Copyright (c) 2002-2023, by Derick Rethans
with Zend OPcache v8.3.0, Copyright (c), by Zend Technologies
"""
let shell = TestableShell(expectations: [
"php -v": .instant(expectedOutput),
"echo $PATH": .instant("/Users/user/bin:/opt/homebrew/bin")
])
XCTAssertEqual(expectedOutput, shell.sync("php -v").out)
XCTAssertEqual("/Users/user/bin:/opt/homebrew/bin", shell.sync("echo $PATH").out)
}
func test_fake_shell_has_path() {
ActiveShell.useTestable([:])