TestStream
in package
implements
StreamInterface
Test stream implementation for unit testing.
Provides an in-memory stream implementation that can be pre-programmed with inputs and captures all outputs. Useful for testing interactive CLI operations without requiring actual terminal interaction.
Table of Contents
Interfaces
- StreamInterface
- Interface for input/output stream abstraction.
Properties
- $inputs : array<int, string>
- $interactive : bool
- $outputs : array<int, string>
- $position : int
Methods
- clearOutputs() : void
- Clear captured outputs
- getOutput() : string
- Get all outputs as a single string
- getOutputs() : array<int, string>
- Get all captured outputs
- isInteractive() : bool
- Check if the stream is connected to an interactive terminal
- read() : string|false
- Read a line from the input stream
- reset() : void
- Reset the stream to initial state
- setInputs() : void
- Set pre-programmed inputs for testing
- setInteractive() : void
- Set whether this stream should report as interactive
- write() : void
- Write data to the output stream
Properties
$inputs
private
array<int, string>
$inputs
= []
Pre-programmed inputs to return
$interactive
private
bool
$interactive
= true
Whether this stream is interactive
$outputs
private
array<int, string>
$outputs
= []
Captured outputs
$position
private
int
$position
= 0
Current position in inputs array
Methods
clearOutputs()
Clear captured outputs
public
clearOutputs() : void
getOutput()
Get all outputs as a single string
public
getOutput() : string
Return values
stringgetOutputs()
Get all captured outputs
public
getOutputs() : array<int, string>
Return values
array<int, string>isInteractive()
Check if the stream is connected to an interactive terminal
public
isInteractive() : bool
Tags
Return values
bool —True if interactive (TTY), false otherwise
read()
Read a line from the input stream
public
read() : string|false
Tags
Return values
string|false —Returns the read line or false on EOF
reset()
Reset the stream to initial state
public
reset() : void
setInputs()
Set pre-programmed inputs for testing
public
setInputs(array<int, string> $inputs) : void
Parameters
- $inputs : array<int, string>
-
Array of input strings to return
setInteractive()
Set whether this stream should report as interactive
public
setInteractive(bool $interactive) : void
Parameters
- $interactive : bool
write()
Write data to the output stream
public
write(string $data) : void
Parameters
- $data : string
-
Data to write