Skip to content

Commit

Permalink
replace deprecated getMock in tests and generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Jul 14, 2016
1 parent f0aea21 commit 0702f69
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 156 deletions.
12 changes: 7 additions & 5 deletions src/Shell/Task/TestTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,18 @@ public function generateConstructor($type, $fullClassName)
$construct = "new {$className}(\$registry);";
}
if ($type === 'shell') {
$pre = "\$this->io = \$this->getMock('Cake\Console\ConsoleIo');";
$pre = "\$this->io = \$this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();";
$construct = "new {$className}(\$this->io);";
}
if ($type === 'task') {
$pre = "\$this->io = \$this->getMock('Cake\Console\ConsoleIo');\n";
$construct = "\$this->getMock('{$fullClassName}', [], [\$this->io]);";
$pre = "\$this->io = \$this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();\n";
$construct = "\$this->getMockBuilder('{$fullClassName}')\n";
$construct .= " ->setConstructorArgs([\$this->io])\n";
$construct .= " ->getMock();";
}
if ($type === 'cell') {
$pre = "\$this->request = \$this->getMock('Cake\Network\Request');\n";
$pre .= " \$this->response = \$this->getMock('Cake\Network\Response');";
$pre = "\$this->request = \$this->getMockBuilder('Cake\Network\Request')->getMock();\n";
$pre .= " \$this->response = \$this->getMockBuilder('Cake\Network\Response')->getMock();";
$construct = "new {$className}(\$this->request, \$this->response);";
}
if ($type === 'shell_helper') {
Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Shell/BakeShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public function setUp()
$this->out = new ConsoleOutput();
$this->io = new ConsoleIo($this->out);

$this->Shell = $this->getMock(
'Bake\Shell\BakeShell',
['in', 'createFile', '_stop'],
[$this->io]
);
$this->Shell = $this->getMockBuilder('Bake\Shell\BakeShell')
->setMethods(['in', 'createFile', '_stop'])
->setConstructorArgs([$this->io])
->getMock();

Configure::write('App.namespace', 'Bake\Test\App');
}

Expand All @@ -81,9 +81,9 @@ public function tearDown()
*/
public function testAllWithModelName()
{
$this->Shell->Model = $this->getMock('Bake\Shell\Task\ModelTask');
$this->Shell->Controller = $this->getMock('Bake\Shell\Task\ControllerTask');
$this->Shell->Template = $this->getMock('Bake\Shell\Task\TemplateTask');
$this->Shell->Model = $this->getMockBuilder('Bake\Shell\Task\ModelTask')->getMock();
$this->Shell->Controller = $this->getMockBuilder('Bake\Shell\Task\ControllerTask')->getMock();
$this->Shell->Template = $this->getMockBuilder('Bake\Shell\Task\TemplateTask')->getMock();

$this->Shell->Model->expects($this->once())
->method('main')
Expand Down
14 changes: 8 additions & 6 deletions tests/TestCase/Shell/Task/BakeTemplateTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'BakeTemplate' . DS;
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\BakeTemplateTask',
['in', 'err', 'createFile', '_stop', 'clear'],
[$io]
);
$this->Task = $this->getMockBuilder('Bake\Shell\Task\BakeTemplateTask')
->setMethods(['in', 'err', 'createFile', '_stop', 'clear'])
->setConstructorArgs([$io])
->getMock();
;
}

/**
Expand Down
23 changes: 12 additions & 11 deletions tests/TestCase/Shell/Task/CellTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Cell' . DS;
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMockBuilder('Bake\Shell\Task\CellTask')
->setMethods(['in', 'err', 'createFile', '_stop'])
->setConstructorArgs([$io])
->getMock();

$this->Task->Test = $this->getMockBuilder('Bake\Shell\Task\TestTask')
->setConstructorArgs([$io])
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\CellTask',
['in', 'err', 'createFile', '_stop'],
[$io]
);
$this->Task->Test = $this->getMock(
'Bake\Shell\Task\TestTask',
[],
[$io]
);
$this->Task->BakeTemplate = new BakeTemplateTask($io);
$this->Task->BakeTemplate->initialize();
$this->Task->BakeTemplate->interactive = false;
Expand Down
32 changes: 16 additions & 16 deletions tests/TestCase/Shell/Task/ControllerTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Controller' . DS;
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$this->Task = $this->getMock(
'Bake\Shell\Task\ControllerTask',
['in', 'out', 'err', 'hr', 'createFile', '_stop'],
[$io]
);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();
$this->Task = $this->getMockBuilder('Bake\Shell\Task\ControllerTask')
->setMethods(['in', 'out', 'err', 'hr', 'createFile', '_stop'])
->setConstructorArgs([$io])
->getMock();

$this->Task->name = 'Controller';
$this->Task->connection = 'test';

$this->Task->BakeTemplate = new BakeTemplateTask($io);

$this->Task->Model = $this->getMock(
'Bake\Shell\Task\ModelTask',
['in', 'out', 'err', 'createFile', '_stop'],
[$io]
);
$this->Task->Test = $this->getMock(
'Bake\Shell\Task\TestTask',
[],
[$io]
);
$this->Task->Model = $this->getMockBuilder('Bake\Shell\Task\ModelTask')
->setMethods(['in', 'out', 'err', 'createFile', '_stop'])
->setConstructorArgs([$io])
->getMock();

$this->Task->Test = $this->getMockBuilder('Bake\Shell\Task\TestTask')
->setConstructorArgs([$io])
->getMock();

TableRegistry::get('BakeArticles', [
'className' => __NAMESPACE__ . '\BakeArticlesTable'
Expand Down
24 changes: 12 additions & 12 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ class FixtureTaskTest extends TestCase
public function setUp()
{
parent::setUp();
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);

$this->Task = $this->getMock(
'Bake\Shell\Task\FixtureTask',
['in', 'err', 'createFile', '_stop', 'clear'],
[$io]
);
$this->Task->Model = $this->getMock(
'Bake\Shell\Task\ModelTask',
['in', 'out', 'err', 'createFile', 'getName', 'getTable', 'listUnskipped'],
[$io]
);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMockBuilder('Bake\Shell\Task\FixtureTask')
->setMethods(['in', 'err', 'createFile', '_stop', 'clear'])
->setConstructorArgs([$io])
->getMock();
$this->Task->Model = $this->getMockBuilder('Bake\Shell\Task\ModelTask')
->setMethods(['in', 'out', 'err', 'createFile', 'getName', 'getTable', 'listUnskipped'])
->setConstructorArgs([$io])
->getMock();
$this->Task->BakeTemplate = new BakeTemplateTask($io);
$this->Task->BakeTemplate->interactive = false;
$this->Task->BakeTemplate->initialize();
Expand Down
26 changes: 14 additions & 12 deletions tests/TestCase/Shell/Task/MailerTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Mailer' . DS;
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);

$this->Task = $this->getMock(
'Bake\Shell\Task\MailerTask',
['in', 'err', 'createFile', '_stop'],
[$io]
);
$this->Task->Test = $this->getMock(
'Bake\Shell\Task\TestTask',
[],
[$io]
);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();


$this->Task = $this->getMockBuilder('Bake\Shell\Task\MailerTask')
->setMethods(['in', 'err', 'createFile', '_stop'])
->setConstructorArgs([$io])
->getMock();

$this->Task->Test = $this->getMockBuilder('Bake\Shell\Task\TestTask')
->setConstructorArgs([$io])
->getMock();

$this->Task->BakeTemplate = new BakeTemplateTask($io);
$this->Task->BakeTemplate->initialize();
$this->Task->BakeTemplate->interactive = false;
Expand Down
42 changes: 26 additions & 16 deletions tests/TestCase/Shell/Task/ModelTaskAssociationDetectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS;
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMockBuilder('Bake\Shell\Task\ModelTask')
->setMethods(['in', 'err', 'createFile', '_stop', '_checkUnitTest'])
->setConstructorArgs([$io])
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\ModelTask',
['in', 'err', 'createFile', '_stop', '_checkUnitTest'],
[$io]
);
$this->Task->connection = 'default';
$this->_setupOtherMocks();
TableRegistry::clear();
Expand All @@ -75,13 +77,15 @@ public function setUp()
*/
protected function _useMockedOut()
{
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMockBuilder('Bake\Shell\Task\ModelTask')
->setMethods(['in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'])
->setConstructorArgs([$io])
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\ModelTask',
['in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'],
[$io]
);
$this->_setupOtherMocks();
}

Expand All @@ -92,10 +96,16 @@ protected function _useMockedOut()
*/
protected function _setupOtherMocks()
{
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);

$this->Task->Fixture = $this->getMock('Bake\Shell\Task\FixtureTask', [], [$io]);
$this->Task->Test = $this->getMock('Bake\Shell\Task\FixtureTask', [], [$io]);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task->Fixture = $this->getMockBuilder('Bake\Shell\Task\FixtureTask')
->setConstructorArgs([$io])
->getMock();
$this->Task->Test = $this->getMockBuilder('Bake\Shell\Task\FixtureTask')
->setConstructorArgs([$io])
->getMock();
$this->Task->BakeTemplate = new BakeTemplateTask($io);
$this->Task->BakeTemplate->interactive = false;

Expand Down
42 changes: 26 additions & 16 deletions tests/TestCase/Shell/Task/ModelTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS;
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMockBuilder('Bake\Shell\Task\ModelTask')
->setMethods(['in', 'err', 'createFile', '_stop', '_checkUnitTest'])
->setConstructorArgs([$io])
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\ModelTask',
['in', 'err', 'createFile', '_stop', '_checkUnitTest'],
[$io]
);
$this->Task->connection = 'test';
$this->_setupOtherMocks();
TableRegistry::clear();
Expand All @@ -89,13 +91,15 @@ public function setUp()
*/
protected function _useMockedOut()
{
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMockBuilder('Bake\Shell\Task\ModelTask')
->setMethods(['in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'])
->setConstructorArgs([$io])
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\ModelTask',
['in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'],
[$io]
);
$this->_setupOtherMocks();
}

Expand All @@ -106,10 +110,16 @@ protected function _useMockedOut()
*/
protected function _setupOtherMocks()
{
$io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);

$this->Task->Fixture = $this->getMock('Bake\Shell\Task\FixtureTask', [], [$io]);
$this->Task->Test = $this->getMock('Bake\Shell\Task\FixtureTask', [], [$io]);
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task->Fixture = $this->getMockBuilder('Bake\Shell\Task\FixtureTask')
->setConstructorArgs([$io])
->getMock();
$this->Task->Test = $this->getMockBuilder('Bake\Shell\Task\FixtureTask')
->setConstructorArgs([$io])
->getMock();
$this->Task->BakeTemplate = new BakeTemplateTask($io);
$this->Task->BakeTemplate->interactive = false;

Expand Down
23 changes: 12 additions & 11 deletions tests/TestCase/Shell/Task/PluginTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ public function setUp()
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Plugin' . DS;
$this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')
->disableOriginalConstructor()
->getMock();

$this->Task = $this->getMock(
'Bake\Shell\Task\PluginTask',
['in', 'err', '_stop', 'clear', 'callProcess', '_rootComposerFilePath', 'findComposer'],
[$this->io]
);
$this->Task = $this->getMockBuilder('Bake\Shell\Task\PluginTask')
->setMethods(['in', 'err', '_stop', 'clear', 'callProcess', '_rootComposerFilePath', 'findComposer'])
->setConstructorArgs([$this->io])
->getMock();

$this->Task->BakeTemplate = new BakeTemplateTask($this->io);
$this->Task->BakeTemplate->interactive = false;
Expand Down Expand Up @@ -194,11 +195,11 @@ public function testFindPathNonExistent()
array_unshift($paths, '/fake/path');
$paths[] = '/fake/path2';

$this->Task = $this->getMock(
'Bake\Shell\Task\PluginTask',
['in', 'out', 'err', '_stop'],
[$this->io]
);
$this->Task = $this->getMockBuilder('Bake\Shell\Task\PluginTask')
->setMethods(['in', 'out', 'err', '_stop'])
->setConstructorArgs([$this->io])
->getMock();

$this->Task->path = TMP . 'tests' . DS;

$this->Task->method('findPath')
Expand Down
Loading

0 comments on commit 0702f69

Please sign in to comment.