Trait luya\testsuite\traits\CommandStdStreamTrait
| Available since version | 1.0.19 |
|---|---|
| Source Code | https://github.com/luyadev/luya-testsuite/blob/master/src/traits/CommandStdStreamTrait.php |
Console trait for {{\luya\console\Command}} stubs to replacement STDIN/STDOUT/STDERR with a array stack.
Example
class ControllerStub extend Controller
{
use CommandStdStreamTrait;
public function testUserAbort()
{
$controller = new ControllerStub();
// send a user input for the first prompt
$controller->sendInput('yes');
// send a user input for the second prompt
$controller->sendInput('no');
$controller->actionIndex();
$this->assertEquals('User answer with yes.', $controller->readOutput());
$this->assertEquals('User answer with no.', $controller->readOutput());
}
}
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $errorStream | array | Error stream | luya\testsuite\traits\CommandStdStreamTrait |
| $inputStream | array | Input stream | luya\testsuite\traits\CommandStdStreamTrait |
| $outputStream | array | Output stream | luya\testsuite\traits\CommandStdStreamTrait |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| confirm() | Replace {{\yii\console\Controller::confirm}} function. | luya\testsuite\traits\CommandStdStreamTrait |
| prompt() | Replace {{\yii\console\Controller::prompt}} function. | luya\testsuite\traits\CommandStdStreamTrait |
| readError() | Read data from console error outpur stream | luya\testsuite\traits\CommandStdStreamTrait |
| readOutput() | Read data from console output stream | luya\testsuite\traits\CommandStdStreamTrait |
| select() | Replace {{\yii\console\Controller::select}} function. | luya\testsuite\traits\CommandStdStreamTrait |
| sendInput() | Write passed input to the console input stream. | luya\testsuite\traits\CommandStdStreamTrait |
| stderr() | Replace the {{\yii\console\Controller::stderr}} function. | luya\testsuite\traits\CommandStdStreamTrait |
| stdin() | Replace the {{\yii\console\Controller::stdin}} function. | luya\testsuite\traits\CommandStdStreamTrait |
| stdout() | Replace the {{\yii\console\Controller::stdout}} function. | luya\testsuite\traits\CommandStdStreamTrait |
| truncateStreams() | Clean the console streams | luya\testsuite\traits\CommandStdStreamTrait |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| output() | Replace the {{\luya\console\Controller::output}} function. | luya\testsuite\traits\CommandStdStreamTrait |
Property Details
Method Details
Replace {{\yii\console\Controller::confirm}} function.
| public boolean confirm ( $message, $default = false ) | ||
| $message | ||
| $default | boolean | |
public function confirm($message, $default = false)
{
return $this->stdin() == 'yes';
}
Replace the {{\luya\console\Controller::output}} function.
| protected void output ( $message, $color = null ) | ||
| $message | ||
| $color | null | |
protected function output($message, $color = null)
{
$this->outputStream[] = $message;
}
Replace {{\yii\console\Controller::prompt}} function.
| public mixed|string prompt ( $text, $options = [] ) | ||
| $text | ||
| $options | array | |
public function prompt($text, $options = [])
{
return $this->stdin();
}
Read data from console error outpur stream
| public string readError ( ) |
public function readError()
{
return array_shift($this->errorStream);
}
Read data from console output stream
| public string readOutput ( ) |
public function readOutput()
{
return array_shift($this->outputStream);
}
Replace {{\yii\console\Controller::select}} function.
| public mixed|string select ( $prompt, $options = [] ) | ||
| $prompt | ||
| $options | array | |
public function select($prompt, $options = [])
{
return $this->stdin();
}
Write passed input to the console input stream.
| public void sendInput ( string $input ) | ||
| $input | string | |
public function sendInput(string $input)
{
$this->inputStream[] = $input;
}
Replace the {{\yii\console\Controller::stderr}} function.
| public void stderr ( $string ) | ||
| $string | ||
public function stderr($string)
{
$this->errorStream[] = $string;
}
Replace the {{\yii\console\Controller::stdin}} function.
| public mixed|string stdin ( $raw = false ) | ||
| $raw | boolean | |
public function stdin($raw = false)
{
return $raw ? array_shift($this->inputStream) : rtrim((string) array_shift($this->inputStream), PHP_EOL);
}
Replace the {{\yii\console\Controller::stdout}} function.
| public void stdout ( $string ) | ||
| $string | ||
public function stdout($string)
{
$this->outputStream[] = $string;
}
Clean the console streams
| public void truncateStreams ( ) |
public function truncateStreams()
{
$this->inputStream = [];
$this->outputStream = [];
$this->errorStream = [];
}