Skip to content
Permalink
Browse files

Don't output two welcome messages.

Make the dispatched shell task as 'requested'. This disables the welcome
message being output by the task. The containing shell will take care of
emiting the welcome message.

Refs #8600
  • Loading branch information...
markstory committed Apr 7, 2016
1 parent 91799c4 commit 5fb587b44309a6f237176e7931e16569df56cc00
Showing with 37 additions and 2 deletions.
  1. +1 −1 src/Console/Shell.php
  2. +36 −1 tests/TestCase/Console/ShellTest.php
@@ -447,7 +447,7 @@ public function runCommand($argv, $autoMethod = false, $extra = [])
if ($this->hasTask($command) && isset($subcommands[$command])) {
$this->startup();
array_shift($argv);
return $this->{$method}->runCommand($argv, false);
return $this->{$method}->runCommand($argv, false, ['requested' => true]);
}
if ($this->hasMethod('main')) {
@@ -1066,7 +1066,7 @@ public function testRunCommandHittingTaskInSubcommand()
$task->io($io);
$task->expects($this->once())
->method('runCommand')
->with(['one'], false);
->with(['one'], false, ['requested' => true]);
$shell->expects($this->once())->method('getOptionParser')
->will($this->returnValue($parser));
@@ -1080,6 +1080,41 @@ public function testRunCommandHittingTaskInSubcommand()
$shell->runCommand(['slice', 'one']);
}
/**
* test that runCommand will invoke a task
*
* @return void
*/
public function testRunCommandInvokeTask()
{
$parser = new ConsoleOptionParser('knife');
$parser->addSubcommand('slice');
$io = $this->getMock('Cake\Console\ConsoleIo');
$shell = $this->getMock('Cake\Console\Shell', ['hasTask', 'getOptionParser'], [$io]);
$task = $this->getMock('Cake\Console\Shell', ['main', '_welcome'], [$io]);
$shell->expects($this->once())
->method('getOptionParser')
->will($this->returnValue($parser));
$shell->expects($this->any())
->method('hasTask')
->will($this->returnValue(true));
$task->expects($this->never())
->method('_welcome');
// One welcome message output.
$io->expects($this->at(2))
->method('out')
->with($this->stringContains('Welcome to CakePHP'));
$shell->Slice = $task;
$shell->runCommand(['slice', 'one']);
$this->assertTrue($task->params['requested'], 'Task is requested, no welcome.');
}
/**
* test wrapBlock wrapping text.
*

0 comments on commit 5fb587b

Please sign in to comment.
You can’t perform that action at this time.