Skip to content

Commit

Permalink
Split ConsoleOutput::outputAs() into getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hoffmann committed Apr 10, 2017
1 parent b891683 commit 360c7e5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Console/ConsoleIo.php
Expand Up @@ -266,7 +266,7 @@ public function ask($prompt, $default = null)
*/
public function outputAs($mode)
{
$this->_out->outputAs($mode);
$this->_out->setOutputAs($mode);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/Console/ConsoleOutput.php
Expand Up @@ -302,9 +302,31 @@ public function styles($style = null, $definition = null)
return true;
}

/**
* Get the output type on how formatting tags are treated.
*
* @return int
*/
public function getOutputAs()
{
return $this->_outputAs;
}

/**
* Set the output type on how formatting tags are treated.
*
* @param int $type The output type to use. Should be one of the class constants.
* @return void
*/
public function setOutputAs($type)
{
$this->_outputAs = $type;
}

/**
* Get/Set the output type to use. The output type how formatting tags are treated.
*
* @deprecated 3.5.0 Use getOutputAs()/setOutputAs() instead.
* @param int|null $type The output type to use. Should be one of the class constants.
* @return int|null Either null or the value if getting.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Shell.php
Expand Up @@ -509,7 +509,7 @@ protected function _displayHelp($command)
$format = 'text';
if (!empty($this->args[0]) && $this->args[0] === 'xml') {
$format = 'xml';
$this->_io->outputAs(ConsoleOutput::RAW);
$this->_io->setOutputAs(ConsoleOutput::RAW);
} else {
$this->_welcome();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Console/ConsoleOutputTest.php
Expand Up @@ -249,6 +249,20 @@ public function testOutputAsPlain()
$this->output->write('<error>Bad</error> Regular', false);
}

/**
* test set plain output.
*
* @return void
*/
public function testSetOutputAsPlain()
{
$this->output->setOutputAs(ConsoleOutput::PLAIN);
$this->output->expects($this->once())->method('_write')
->with('Bad Regular');

$this->output->write('<error>Bad</error> Regular', false);
}

/**
* test plain output only strips tags used for formatting.
*
Expand Down

0 comments on commit 360c7e5

Please sign in to comment.