Browse Source

Remove use of TestCase::getMock() from "Console" namepace tests.

ADmad 9 years ago
parent
commit
8dcf70d29d

+ 8 - 3
tests/TestCase/Console/ConsoleErrorHandlerTest.php

@@ -30,13 +30,18 @@ class ConsoleErrorHandlerTest extends TestCase
     /**
      * setup, create mocks
      *
-     * @return Mock object
+     * @return void
      */
     public function setUp()
     {
         parent::setUp();
-        $this->stderr = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
-        $this->Error = $this->getMock('Cake\Console\ConsoleErrorHandler', ['_stop'], [['stderr' => $this->stderr]]);
+        $this->stderr = $this->getMockBuilder('Cake\Console\ConsoleOutput')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $this->Error = $this->getMockBuilder('Cake\Console\ConsoleErrorHandler')
+            ->setMethods(['_stop'])
+            ->setConstructorArgs([['stderr' => $this->stderr]])
+            ->getMock();
         Log::drop('stderr');
     }
 

+ 9 - 3
tests/TestCase/Console/ConsoleIoTest.php

@@ -35,9 +35,15 @@ class ConsoleIoTest extends TestCase
         parent::setUp();
         Configure::write('App.namespace', 'TestApp');
 
-        $this->out = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
-        $this->err = $this->getMock('Cake\Console\ConsoleOutput', [], [], '', false);
-        $this->in = $this->getMock('Cake\Console\ConsoleInput', [], [], '', false);
+        $this->out = $this->getMockBuilder('Cake\Console\ConsoleOutput')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $this->err = $this->getMockBuilder('Cake\Console\ConsoleOutput')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $this->in = $this->getMockBuilder('Cake\Console\ConsoleInput')
+            ->disableOriginalConstructor()
+            ->getMock();
         $this->io = new ConsoleIo($this->out, $this->err, $this->in);
     }
 

+ 3 - 1
tests/TestCase/Console/ConsoleOutputTest.php

@@ -34,7 +34,9 @@ class ConsoleOutputTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->output = $this->getMock('Cake\Console\ConsoleOutput', ['_write']);
+        $this->output = $this->getMockBuilder('Cake\Console\ConsoleOutput')
+            ->setMethods(['_write'])
+            ->getMock();
         $this->output->outputAs(ConsoleOutput::COLOR);
     }
 

+ 3 - 1
tests/TestCase/Console/HelperRegistryTest.php

@@ -34,7 +34,9 @@ class HelperRegistryTest extends TestCase
     {
         parent::setUp();
         Configure::write('App.namespace', 'TestApp');
-        $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
+        $io = $this->getMockBuilder('Cake\Console\ConsoleIo')
+            ->disableOriginalConstructor()
+            ->getMock();
         $this->helpers = new HelperRegistry();
         $this->helpers->setIo($io);
     }

+ 37 - 21
tests/TestCase/Console/ShellDispatcherTest.php

@@ -36,7 +36,9 @@ class ShellDispatcherTest extends TestCase
         parent::setUp();
         Plugin::load('TestPlugin');
         Configure::write('App.namespace', 'TestApp');
-        $this->dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['_stop']);
+        $this->dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['_stop'])
+            ->getMock();
     }
 
     /**
@@ -155,14 +157,19 @@ class ShellDispatcherTest extends TestCase
     public function testDispatchShellWithAbort()
     {
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['main'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['main'])
+            ->setConstructorArgs([$io])
+            ->getMock();
         $shell->expects($this->once())
             ->method('main')
             ->will($this->returnCallback(function () use ($shell) {
                 $shell->abort('Bad things', 99);
             }));
 
-        $dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell']);
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell'])
+            ->getMock();
         $dispatcher->expects($this->any())
             ->method('findShell')
             ->with('aborter')
@@ -180,7 +187,9 @@ class ShellDispatcherTest extends TestCase
      */
     public function testDispatchShellWithMain()
     {
-        $dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell']);
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell'])
+            ->getMock();
         $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
 
         $Shell->expects($this->exactly(2))->method('initialize');
@@ -212,7 +221,9 @@ class ShellDispatcherTest extends TestCase
      */
     public function testDispatchShellWithoutMain()
     {
-        $dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell']);
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell'])
+            ->getMock();
         $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
 
         $Shell->expects($this->once())->method('initialize');
@@ -237,10 +248,9 @@ class ShellDispatcherTest extends TestCase
      */
     public function testDispatchShortPluginAlias()
     {
-        $dispatcher = $this->getMock(
-            'Cake\Console\ShellDispatcher',
-            ['_shellExists', '_createShell']
-        );
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['_shellExists', '_createShell'])
+            ->getMock();
         $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
 
         $dispatcher->expects($this->at(1))
@@ -265,10 +275,9 @@ class ShellDispatcherTest extends TestCase
      */
     public function testDispatchShortPluginAliasCamelized()
     {
-        $dispatcher = $this->getMock(
-            'Cake\Console\ShellDispatcher',
-            ['_shellExists', '_createShell']
-        );
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['_shellExists', '_createShell'])
+            ->getMock();
         $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
 
         $dispatcher->expects($this->at(1))
@@ -293,10 +302,9 @@ class ShellDispatcherTest extends TestCase
      */
     public function testDispatchShortPluginAliasConflict()
     {
-        $dispatcher = $this->getMock(
-            'Cake\Console\ShellDispatcher',
-            ['_shellExists', '_createShell']
-        );
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['_shellExists', '_createShell'])
+            ->getMock();
         $Shell = $this->getMockBuilder('Cake\Console\Shell')->getMock();
 
         $dispatcher->expects($this->at(1))
@@ -349,11 +357,15 @@ class ShellDispatcherTest extends TestCase
      */
     public function testHelpOption()
     {
-        $mockShell = $this->getMock('Cake\Shell\CommandListShell', ['main', 'initialize', 'startup']);
+        $mockShell = $this->getMockBuilder('Cake\Shell\CommandListShell')
+            ->setMethods(['main', 'initialize', 'startup'])
+            ->getMock();
         $mockShell->expects($this->once())
             ->method('main');
 
-        $dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell', '_stop']);
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell', '_stop'])
+            ->getMock();
         $dispatcher->expects($this->once())
             ->method('findShell')
             ->with('command_list')
@@ -369,11 +381,15 @@ class ShellDispatcherTest extends TestCase
      */
     public function testVersionOption()
     {
-        $mockShell = $this->getMock('Cake\Shell\CommandListShell', ['main', 'initialize', 'startup']);
+        $mockShell = $this->getMockBuilder('Cake\Shell\CommandListShell')
+            ->setMethods(['main', 'initialize', 'startup'])
+            ->getMock();
         $mockShell->expects($this->once())
             ->method('main');
 
-        $dispatcher = $this->getMock('Cake\Console\ShellDispatcher', ['findShell', '_stop']);
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->setMethods(['findShell', '_stop'])
+            ->getMock();
         $dispatcher->expects($this->once())
             ->method('findShell')
             ->with('command_list')

+ 88 - 27
tests/TestCase/Console/ShellTest.php

@@ -44,7 +44,7 @@ class ShellTestShell extends Shell
     /**
      * name property
      *
-     * @var name
+     * @var string
      */
     public $name = 'ShellTestShell';
 
@@ -143,7 +143,9 @@ class ShellTest extends TestCase
     {
         parent::setUp();
 
-        $this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
+        $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')
+            ->disableOriginalConstructor()
+            ->getMock();
         $this->Shell = new ShellTestShell($this->io);
 
         if (is_dir(TMP . 'shell_test')) {
@@ -683,7 +685,10 @@ class ShellTest extends TestCase
     public function testRunCommandMain()
     {
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['main', 'startup'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['main', 'startup'])
+            ->setConstructorArgs([$io])
+            ->getMock();
 
         $shell->expects($this->once())->method('startup');
         $shell->expects($this->once())->method('main')
@@ -702,7 +707,10 @@ class ShellTest extends TestCase
     public function testRunCommandWithMethod()
     {
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['hitMe', 'startup'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['hitMe', 'startup'])
+            ->setConstructorArgs([$io])
+            ->getMock();
 
         $shell->expects($this->once())->method('startup');
         $shell->expects($this->once())->method('hitMe')
@@ -723,9 +731,15 @@ class ShellTest extends TestCase
      */
     public function testRunCommandWithExtra()
     {
-        $Parser = $this->getMock('Cake\Console\ConsoleOptionParser', ['help'], ['knife']);
+        $Parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->setMethods(['help'])
+            ->setConstructorArgs(['knife'])
+            ->getMock();
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $Shell = $this->getMock('Cake\Console\Shell', ['getOptionParser', 'slice', '_welcome', 'param'], [$io]);
+        $Shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['getOptionParser', 'slice', '_welcome', 'param'])
+            ->setConstructorArgs([$io])
+            ->getMock();
         $Parser->addSubCommand('slice');
         $Shell->expects($this->once())
             ->method('getOptionParser')
@@ -866,7 +880,10 @@ TEXT;
     public function testRunCommandAutoMethodOff()
     {
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['hit_me', 'startup'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['hit_me', 'startup'])
+            ->setConstructorArgs([$io])
+            ->getMock();
 
         $shell->expects($this->never())->method('startup');
         $shell->expects($this->never())->method('hit_me');
@@ -885,9 +902,15 @@ TEXT;
      */
     public function testRunCommandWithMethodNotInSubcommands()
     {
-        $parser = $this->getMock('Cake\Console\ConsoleOptionParser', ['help'], ['knife']);
+        $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->setMethods(['help'])
+            ->setConstructorArgs(['knife'])
+            ->getMock();
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['getOptionParser', 'roll', 'startup'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['getOptionParser', 'roll', 'startup'])
+            ->setConstructorArgs([$io])
+            ->getMock();
 
         $parser->addSubCommand('slice');
 
@@ -912,9 +935,15 @@ TEXT;
      */
     public function testRunCommandWithMethodInSubcommands()
     {
-        $parser = $this->getMock('Cake\Console\ConsoleOptionParser', ['help'], ['knife']);
+        $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->setMethods(['help'])
+            ->setConstructorArgs(['knife'])
+            ->getMock();
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['getOptionParser', 'slice', 'startup'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['getOptionParser', 'slice', 'startup'])
+            ->setConstructorArgs([$io])
+            ->getMock();
 
         $parser->addSubCommand('slice');
 
@@ -937,11 +966,17 @@ TEXT;
      */
     public function testRunCommandWithMissingMethodInSubcommands()
     {
-        $parser = $this->getMock('Cake\Console\ConsoleOptionParser', ['help'], ['knife']);
+        $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->setMethods(['help'])
+            ->setConstructorArgs(['knife'])
+            ->getMock();
         $parser->addSubCommand('slice');
 
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
-        $shell = $this->getMock('Cake\Console\Shell', ['getOptionParser', 'startup'], [$io]);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['getOptionParser', 'startup'])
+            ->setConstructorArgs([$io])
+            ->getMock();
         $shell->expects($this->any())
             ->method('getOptionParser')
             ->will($this->returnValue($parser));
@@ -967,8 +1002,10 @@ TEXT;
             ->disableOriginalConstructor()
             ->getMock();
 
-        $shell->io($this->getMock('Cake\Console\ConsoleIo'));
-        $parser = $this->getMock('Cake\Console\ConsoleOptionParser', [], [], '', false);
+        $shell->io($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
+        $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->disableOriginalConstructor()
+            ->getMock();
 
         $parser->expects($this->once())->method('help');
         $shell->expects($this->once())->method('getOptionParser')
@@ -990,8 +1027,10 @@ TEXT;
             ->setMethods(['startup', 'getOptionParser', 'out', 'hr'])
             ->disableOriginalConstructor()
             ->getMock();
-        $shell->io($this->getMock('Cake\Console\ConsoleIo'));
-        $parser = $this->getMock('Cake\Console\ConsoleOptionParser', [], [], '', false);
+        $shell->io($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
+        $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->disableOriginalConstructor()
+            ->getMock();
 
         $parser->expects($this->once())->method('help');
         $shell->expects($this->once())->method('getOptionParser')
@@ -1009,14 +1048,19 @@ TEXT;
      */
     public function testRunCommandTriggeringHelp()
     {
-        $parser = $this->getMock('Cake\Console\ConsoleOptionParser', [], [], '', false);
+        $parser = $this->getMockBuilder('Cake\Console\ConsoleOptionParser')
+            ->disableOriginalConstructor()
+            ->getMock();
         $parser->expects($this->once())->method('parse')
             ->with(['--help'])
             ->will($this->returnValue([['help' => true], []]));
         $parser->expects($this->once())->method('help');
 
-        $shell = $this->getMock('Cake\Console\Shell', ['getOptionParser', 'out', 'startup', '_welcome'], [], '', false);
-        $shell->io($this->getMock('Cake\Console\ConsoleIo'));
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['getOptionParser', 'out', 'startup', '_welcome'])
+            ->disableOriginalConstructor()
+            ->getMock();
+        $shell->io($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
         $shell->expects($this->once())->method('getOptionParser')
             ->will($this->returnValue($parser));
         $shell->expects($this->once())->method('out');
@@ -1031,9 +1075,15 @@ TEXT;
      */
     public function testRunCommandNotCallUnexposedTask()
     {
-        $shell = $this->getMock('Cake\Console\Shell', ['startup', 'hasTask', 'out'], [], '', false);
-        $shell->io($this->getMock('Cake\Console\ConsoleIo'));
-        $task = $this->getMock('Cake\Console\Shell', ['runCommand'], [], '', false);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['startup', 'hasTask', 'out'])
+            ->disableOriginalConstructor()
+            ->getMock();
+        $shell->io($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
+        $task = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['runCommand'])
+            ->disableOriginalConstructor()
+            ->getMock();
 
         $task->expects($this->never())
             ->method('runCommand');
@@ -1060,9 +1110,15 @@ TEXT;
         $parser->addSubcommand('slice');
         $io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
 
-        $shell = $this->getMock('Cake\Console\Shell', ['hasTask', 'startup', 'getOptionParser'], [], '', false);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['hasTask', 'startup', 'getOptionParser'])
+            ->disableOriginalConstructor()
+            ->getMock();
         $shell->io($io);
-        $task = $this->getMock('Cake\Console\Shell', ['main', 'runCommand'], [], '', false);
+        $task = $this->getMockBuilder('Cake\Console\Shell')
+            ->setMethods(['main', 'runCommand'])
+            ->disableOriginalConstructor()
+            ->getMock();
         $task->io($io);
         $task->expects($this->once())
             ->method('runCommand')
@@ -1186,7 +1242,9 @@ TEXT;
      */
     public function testQuietLog()
     {
-        $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
+        $io = $this->getMockBuilder('Cake\Console\ConsoleIo')
+            ->disableOriginalConstructor()
+            ->getMock();
         $io->expects($this->once())
             ->method('level')
             ->with(Shell::QUIET);
@@ -1197,7 +1255,10 @@ TEXT;
             ->method('setLoggers')
             ->with(ConsoleIo::QUIET);
 
-        $this->Shell = $this->getMock(__NAMESPACE__ . '\ShellTestShell', ['welcome'], [$io]);
+        $this->Shell = $this->getMockBuilder(__NAMESPACE__ . '\ShellTestShell')
+            ->setMethods(['welcome'])
+            ->setConstructorArgs([$io])
+            ->getMock();
         $this->Shell->runCommand(['foo', '--quiet']);
     }
 

+ 9 - 3
tests/TestCase/Console/TaskRegistryTest.php

@@ -33,7 +33,9 @@ class TaskRegistryTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $shell = $this->getMock('Cake\Console\Shell', [], [], '', false);
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->disableOriginalConstructor()
+            ->getMock();
         $this->Tasks = new TaskRegistry($shell);
     }
 
@@ -81,8 +83,12 @@ class TaskRegistryTest extends TestCase
      */
     public function testLoadPluginTask()
     {
-        $dispatcher = $this->getMock('Cake\Console\ShellDispatcher', [], [], '', false);
-        $shell = $this->getMock('Cake\Console\Shell', [], [], '', false);
+        $dispatcher = $this->getMockBuilder('Cake\Console\ShellDispatcher')
+            ->disableOriginalConstructor()
+            ->getMock();
+        $shell = $this->getMockBuilder('Cake\Console\Shell')
+            ->disableOriginalConstructor()
+            ->getMock();
         Plugin::load('TestPlugin');
         $this->Tasks = new TaskRegistry($shell, $dispatcher);