Skip to content

Commit

Permalink
Remove use of TestCase::getMock() from "Console" namepace tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 4, 2016
1 parent d29af6d commit 8dcf70d
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 59 deletions.
11 changes: 8 additions & 3 deletions tests/TestCase/Console/ConsoleErrorHandlerTest.php
Expand Up @@ -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');
}

Expand Down
12 changes: 9 additions & 3 deletions tests/TestCase/Console/ConsoleIoTest.php
Expand Up @@ -35,9 +35,15 @@ public function setUp()
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);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/Console/ConsoleOutputTest.php
Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/Console/HelperRegistryTest.php
Expand Up @@ -34,7 +34,9 @@ public function setUp()
{
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);
}
Expand Down
58 changes: 37 additions & 21 deletions tests/TestCase/Console/ShellDispatcherTest.php
Expand Up @@ -36,7 +36,9 @@ public function setUp()
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();
}

/**
Expand Down Expand Up @@ -155,14 +157,19 @@ public function testFindShellAliasedAppShadow()
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')
Expand All @@ -180,7 +187,9 @@ public function testDispatchShellWithAbort()
*/
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');
Expand Down Expand Up @@ -212,7 +221,9 @@ public function testDispatchShellWithMain()
*/
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');
Expand All @@ -237,10 +248,9 @@ public function testDispatchShellWithoutMain()
*/
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))
Expand All @@ -265,10 +275,9 @@ public function testDispatchShortPluginAlias()
*/
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))
Expand All @@ -293,10 +302,9 @@ public function testDispatchShortPluginAliasCamelized()
*/
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))
Expand Down Expand Up @@ -349,11 +357,15 @@ public function testShiftArgs()
*/
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')
Expand All @@ -369,11 +381,15 @@ public function testHelpOption()
*/
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')
Expand Down

0 comments on commit 8dcf70d

Please sign in to comment.