From 360c7e5d70ecdf406a4c406131630d3db961afc0 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 10 Apr 2017 22:52:49 +0200 Subject: [PATCH] Split ConsoleOutput::outputAs() into getter/setter --- src/Console/ConsoleIo.php | 2 +- src/Console/ConsoleOutput.php | 22 ++++++++++++++++++++ src/Console/Shell.php | 2 +- tests/TestCase/Console/ConsoleOutputTest.php | 14 +++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Console/ConsoleIo.php b/src/Console/ConsoleIo.php index d452d248364..3f0e60d2523 100644 --- a/src/Console/ConsoleIo.php +++ b/src/Console/ConsoleIo.php @@ -266,7 +266,7 @@ public function ask($prompt, $default = null) */ public function outputAs($mode) { - $this->_out->outputAs($mode); + $this->_out->setOutputAs($mode); } /** diff --git a/src/Console/ConsoleOutput.php b/src/Console/ConsoleOutput.php index 90c2b2a037a..f04a91bc763 100644 --- a/src/Console/ConsoleOutput.php +++ b/src/Console/ConsoleOutput.php @@ -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. */ diff --git a/src/Console/Shell.php b/src/Console/Shell.php index dca6625f67a..34b1a2dd145 100644 --- a/src/Console/Shell.php +++ b/src/Console/Shell.php @@ -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(); } diff --git a/tests/TestCase/Console/ConsoleOutputTest.php b/tests/TestCase/Console/ConsoleOutputTest.php index 57c660f8f43..0853ee01f78 100644 --- a/tests/TestCase/Console/ConsoleOutputTest.php +++ b/tests/TestCase/Console/ConsoleOutputTest.php @@ -249,6 +249,20 @@ public function testOutputAsPlain() $this->output->write('Bad 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('Bad Regular', false); + } + /** * test plain output only strips tags used for formatting. *