Permalink
Browse files

Merge pull request #10925 from cakephp/master-fix-io-array

Fix regression with arrays being passed for IO output.
  • Loading branch information...
markstory committed Jul 20, 2017
2 parents f3f4d8e + 4cafe88 commit 3f2db4aae00814e687cef0f6846377a3838ca93a
Showing with 92 additions and 4 deletions.
  1. +36 −4 src/Console/Shell.php
  2. +56 −0 tests/TestCase/Console/ShellTest.php
View
@@ -665,7 +665,15 @@ public function out($message = null, $newlines = 1, $level = Shell::NORMAL)
*/
public function err($message = null, $newlines = 1)
{
return $this->_io->err('<error>' . $message . '</error>', $newlines);
if (is_array($message)) {
foreach ($message as $k => $v) {
$message[$k] = '<error>' . $v . '</error>';
}
} else {
$message = '<error>' . $message . '</error>';
}
return $this->_io->err($message, $newlines);
}
/**
@@ -679,7 +687,15 @@ public function err($message = null, $newlines = 1)
*/
public function info($message = null, $newlines = 1, $level = Shell::NORMAL)
{
return $this->out('<info>' . $message . '</info>', $newlines, $level);
if (is_array($message)) {
foreach ($message as $k => $v) {
$message[$k] = '<info>' . $v . '</info>';
}
} else {
$message = '<info>' . $message . '</info>';
}
return $this->out($message, $newlines, $level);
}
/**
@@ -692,7 +708,15 @@ public function info($message = null, $newlines = 1, $level = Shell::NORMAL)
*/
public function warn($message = null, $newlines = 1)
{
return $this->_io->err('<warning>' . $message . '</warning>', $newlines);
if (is_array($message)) {
foreach ($message as $k => $v) {
$message[$k] = '<warning>' . $v . '</warning>';
}
} else {
$message = '<warning>' . $message . '</warning>';
}
return $this->_io->err($message, $newlines);
}
/**
@@ -706,7 +730,15 @@ public function warn($message = null, $newlines = 1)
*/
public function success($message = null, $newlines = 1, $level = Shell::NORMAL)
{
return $this->out('<success>' . $message . '</success>', $newlines, $level);
if (is_array($message)) {
foreach ($message as $k => $v) {
$message[$k] = '<success>' . $v . '</success>';
}
} else {
$message = '<success>' . $message . '</success>';
}
return $this->out($message, $newlines, $level);
}
/**
@@ -309,6 +309,20 @@ public function testErr()
$this->Shell->err('Just a test');
}
/**
* testErr method with array
*
* @return void
*/
public function testErrArray()
{
$this->io->expects($this->once())
->method('err')
->with(['<error>Just</error>', '<error>a</error>', '<error>test</error>'], 1);
$this->Shell->err(['Just', 'a', 'test']);
}
/**
* testInfo method
*
@@ -323,6 +337,20 @@ public function testInfo()
$this->Shell->info('Just a test');
}
/**
* testInfo method with array
*
* @return void
*/
public function testInfoArray()
{
$this->io->expects($this->once())
->method('out')
->with(['<info>Just</info>', '<info>a</info>', '<info>test</info>'], 1);
$this->Shell->info(['Just', 'a', 'test']);
}
/**
* testWarn method
*
@@ -337,6 +365,20 @@ public function testWarn()
$this->Shell->warn('Just a test');
}
/**
* testWarn method with array
*
* @return void
*/
public function testWarnArray()
{
$this->io->expects($this->once())
->method('err')
->with(['<warning>Just</warning>', '<warning>a</warning>', '<warning>test</warning>'], 1);
$this->Shell->warn(['Just', 'a', 'test']);
}
/**
* testSuccess method
*
@@ -351,6 +393,20 @@ public function testSuccess()
$this->Shell->success('Just a test');
}
/**
* testSuccess method with array
*
* @return void
*/
public function testSuccessArray()
{
$this->io->expects($this->once())
->method('out')
->with(['<success>Just</success>', '<success>a</success>', '<success>test</success>'], 1);
$this->Shell->success(['Just', 'a', 'test']);
}
/**
* testNl
*

0 comments on commit 3f2db4a

Please sign in to comment.