Skip to content

Commit

Permalink
Adopt new ConsoleIo methods in Shell.
Browse files Browse the repository at this point in the history
Update tests to reflect usage of new methods offered by ConsoleIo
  • Loading branch information
markstory committed Oct 11, 2017
1 parent 3b5f420 commit 4edb83f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
21 changes: 5 additions & 16 deletions src/Console/Shell.php
Expand Up @@ -729,10 +729,7 @@ public function out($message = null, $newlines = 1, $level = Shell::NORMAL)
*/
public function err($message = null, $newlines = 1)
{
$messageType = 'error';
$message = $this->wrapMessageWithType($messageType, $message);

return $this->_io->err($message, $newlines);
return $this->_io->error($message, $newlines);
}

/**
Expand All @@ -746,10 +743,7 @@ public function err($message = null, $newlines = 1)
*/
public function info($message = null, $newlines = 1, $level = Shell::NORMAL)
{
$messageType = 'info';
$message = $this->wrapMessageWithType($messageType, $message);

return $this->out($message, $newlines, $level);
return $this->_io->info($message, $newlines, $level);
}

/**
Expand All @@ -762,10 +756,7 @@ public function info($message = null, $newlines = 1, $level = Shell::NORMAL)
*/
public function warn($message = null, $newlines = 1)
{
$messageType = 'warning';
$message = $this->wrapMessageWithType($messageType, $message);

return $this->_io->err($message, $newlines);
return $this->_io->warning($message, $newlines);
}

/**
Expand All @@ -779,10 +770,7 @@ public function warn($message = null, $newlines = 1)
*/
public function success($message = null, $newlines = 1, $level = Shell::NORMAL)
{
$messageType = 'success';
$message = $this->wrapMessageWithType($messageType, $message);

return $this->out($message, $newlines, $level);
return $this->_io->success($message, $newlines, $level);
}

/**
Expand All @@ -791,6 +779,7 @@ public function success($message = null, $newlines = 1, $level = Shell::NORMAL)
* @param string $messageType The message type, e.g. "warning".
* @param string|array $message The message to wrap.
* @return array|string The message wrapped with the given message type.
* @deprecated 3.6.0 Will be removed in 4.0.0 as it is no longer in use.
*/
protected function wrapMessageWithType($messageType, $message)
{
Expand Down
36 changes: 18 additions & 18 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -303,8 +303,8 @@ public function testOut()
public function testErr()
{
$this->io->expects($this->once())
->method('err')
->with('<error>Just a test</error>', 1);
->method('error')
->with('Just a test', 1);

$this->Shell->err('Just a test');
}
Expand All @@ -317,8 +317,8 @@ public function testErr()
public function testErrArray()
{
$this->io->expects($this->once())
->method('err')
->with(['<error>Just</error>', '<error>a</error>', '<error>test</error>'], 1);
->method('error')
->with(['Just', 'a', 'test'], 1);

$this->Shell->err(['Just', 'a', 'test']);
}
Expand All @@ -331,8 +331,8 @@ public function testErrArray()
public function testInfo()
{
$this->io->expects($this->once())
->method('out')
->with('<info>Just a test</info>', 1);
->method('info')
->with('Just a test', 1);

$this->Shell->info('Just a test');
}
Expand All @@ -345,8 +345,8 @@ public function testInfo()
public function testInfoArray()
{
$this->io->expects($this->once())
->method('out')
->with(['<info>Just</info>', '<info>a</info>', '<info>test</info>'], 1);
->method('info')
->with(['Just', 'a', 'test'], 1);

$this->Shell->info(['Just', 'a', 'test']);
}
Expand All @@ -359,8 +359,8 @@ public function testInfoArray()
public function testWarn()
{
$this->io->expects($this->once())
->method('err')
->with('<warning>Just a test</warning>', 1);
->method('warning')
->with('Just a test', 1);

$this->Shell->warn('Just a test');
}
Expand All @@ -373,8 +373,8 @@ public function testWarn()
public function testWarnArray()
{
$this->io->expects($this->once())
->method('err')
->with(['<warning>Just</warning>', '<warning>a</warning>', '<warning>test</warning>'], 1);
->method('warning')
->with(['Just', 'a', 'test'], 1);

$this->Shell->warn(['Just', 'a', 'test']);
}
Expand All @@ -387,8 +387,8 @@ public function testWarnArray()
public function testSuccess()
{
$this->io->expects($this->once())
->method('out')
->with('<success>Just a test</success>', 1);
->method('success')
->with('Just a test', 1);

$this->Shell->success('Just a test');
}
Expand All @@ -401,8 +401,8 @@ public function testSuccess()
public function testSuccessArray()
{
$this->io->expects($this->once())
->method('out')
->with(['<success>Just</success>', '<success>a</success>', '<success>test</success>'], 1);
->method('success')
->with(['Just', 'a', 'test'], 1);

$this->Shell->success(['Just', 'a', 'test']);
}
Expand Down Expand Up @@ -1271,8 +1271,8 @@ public function testRunCommandMainMissingArgument()
$shell->expects($this->never())->method('main');

$io->expects($this->once())
->method('err')
->with('<error>Error: Missing required arguments. filename is required.</error>');
->method('error')
->with('Error: Missing required arguments. filename is required.');
$result = $shell->runCommand([]);
$this->assertFalse($result, 'Shell should fail');
}
Expand Down

0 comments on commit 4edb83f

Please sign in to comment.