1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-13 22:30:07 +02:00
This commit is contained in:
2022-10-04 17:57:05 +02:00
parent c26c491340
commit 953ccb3792
6 changed files with 52 additions and 93 deletions

View File

@@ -9,54 +9,27 @@
import XCTest
class FakeShellTest: XCTestCase {
func test_fake_shell_output_can_be_declared() {
func test_fake_shell_output_can_be_declared() async {
let greeting = BatchFakeShellOutput(items: [
.instant("Hello world"),
.instant("Hello world\n"),
.delayed(0.3, "Goodbye world")
])
let output = greeting.outputInstantaneously()
let output = await greeting.outputInstantaneously()
XCTAssertEqual("Hello world\nGoodbye world", output.out)
}
/*
func test_we_can_predefine_responses_for_dummy_shell() {
let expectedPhpOutput = """
PHP 8.1.10 (cli) (built: Sep 3 2022 12:09:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.10, Copyright (c) Zend Technologies
with Zend OPcache v8.1.10, Copyright (c), by Zend Technologies
with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans
"""
let slowVersionOutput = FakeTerminalOutput(
output: expectedPhpOutput,
duration: 1000,
isError: false
)
ActiveShell.useTestable([
"php -v": expectedPhpOutput,
"php --version": slowVersionOutput
func test_fake_shell_can_output_in_realtime() async {
let greeting = BatchFakeShellOutput(items: [
.instant("Hello world\n"),
.delayed(2, "Goodbye world")
])
XCTAssertTrue(Shell is TestableShell)
let output = await greeting.output(didReceiveOutput: { output, _ in
print(output)
})
XCTAssertEqual(expectedPhpOutput, Shell.sync("php -v").out)
XCTAssertEqual(expectedPhpOutput, Shell.sync("php --version").out)
XCTAssertEqual("Hello world\nGoodbye world", output.out)
}
func test_unrecognized_commands_output_stderr() {
ActiveShell.useTestable([:])
let output = Shell.sync("unrecognized command")
XCTAssertTrue(output.hasError)
XCTAssertEqual("Unexpected Command", output.err)
XCTAssertEqual("", output.out)
}
*/
}

View File

@@ -33,8 +33,8 @@ class SystemShellTest: XCTestCase {
let (_, shellOutput) = try! await Shell.attach(
"php -r \"echo 'Hello world' . PHP_EOL; usleep(200); echo 'Goodbye world';\"",
didReceiveOutput: { incoming in
bits.append(incoming.out)
didReceiveOutput: { incoming, _ in
bits.append(incoming)
},
withTimeout: 2.0
)
@@ -50,7 +50,7 @@ class SystemShellTest: XCTestCase {
do {
_ = try await Shell.attach(
"php -r \"sleep(1);\"",
didReceiveOutput: { _ in },
didReceiveOutput: { _, _ in },
withTimeout: 0.1
)
} catch {