Browse Source

Merge pull request #8609 from cakephp/less-welcome

Don't display welcome message twice.
Mark Story 10 years ago
parent
commit
9ecb20af2d
2 changed files with 37 additions and 2 deletions
  1. 1 1
      src/Console/Shell.php
  2. 36 1
      tests/TestCase/Console/ShellTest.php

+ 1 - 1
src/Console/Shell.php

@@ -447,7 +447,7 @@ class Shell
         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')) {

+ 36 - 1
tests/TestCase/Console/ShellTest.php

@@ -1066,7 +1066,7 @@ TEXT;
         $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));
@@ -1081,6 +1081,41 @@ TEXT;
     }
 
     /**
+     * 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.
      *
      * @return void