Skip to content

Commit fb37e21

Browse files
committed
Update Shell to use MergeVariablesTrait.
1 parent f108089 commit fb37e21

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

lib/Cake/Console/Shell.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Cake\Utility\ClassRegistry;
2828
use Cake\Utility\File;
2929
use Cake\Utility\Inflector;
30+
use Cake\Utility\MergeVariablesTrait;
3031
use Cake\Utility\String;
3132

3233
/**
@@ -36,6 +37,7 @@
3637
*/
3738
class Shell extends Object {
3839

40+
use MergeVariablesTrait;
3941
/**
4042
* Output constants for making verbose and quiet shells.
4143
*/
@@ -179,13 +181,10 @@ public function __construct($stdout = null, $stderr = null, $stdin = null) {
179181
$this->stdin = new ConsoleInput('php://stdin');
180182
}
181183
$this->_useLogger();
182-
$parent = get_parent_class($this);
183-
if ($this->tasks !== null && $this->tasks !== false) {
184-
$this->_mergeVars(array('tasks'), $parent, true);
185-
}
186-
if ($this->uses !== null && $this->uses !== false) {
187-
$this->_mergeVars(array('uses'), $parent, false);
188-
}
184+
$this->_mergeVars(
185+
['tasks', 'uses'],
186+
['associative' => ['tasks']]
187+
);
189188
}
190189

191190
/**

lib/Cake/Test/TestCase/Console/ShellTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,12 @@ public function log_something() {
7474
}
7575
//@codingStandardsIgnoreEnd
7676

77-
public function mergeVars($properties, $class, $normalize = true) {
78-
return $this->_mergeVars($properties, $class, $normalize);
79-
}
80-
8177
public function useLogger($enable = true) {
8278
$this->_useLogger($enable);
8379
}
8480

8581
}
8682

87-
/**
88-
* Class for testing merging vars
89-
*
90-
* @package Cake.Test.Case.Console.Command
91-
*/
92-
class TestMergeShell extends Shell {
93-
94-
public $tasks = array('DbConfig', 'Fixture');
95-
96-
public $uses = array('Comment');
97-
98-
}
99-
10083
/**
10184
* TestAppleTask class
10285
*
@@ -164,25 +147,6 @@ public function testConstruct() {
164147
$this->assertInstanceOf('Cake\Console\ConsoleOutput', $this->Shell->stderr);
165148
}
166149

167-
/**
168-
* test merging vars
169-
*
170-
* @return void
171-
*/
172-
public function testMergeVars() {
173-
$this->Shell->tasks = array('DbConfig' => array('one', 'two'));
174-
$this->Shell->uses = array('Posts');
175-
$this->Shell->mergeVars(array('tasks'), __NAMESPACE__ . '\TestMergeShell');
176-
$this->Shell->mergeVars(array('uses'), __NAMESPACE__ . '\TestMergeShell', false);
177-
178-
$expected = array('DbConfig' => null, 'Fixture' => null, 'DbConfig' => array('one', 'two'));
179-
$this->assertEquals($expected, $this->Shell->tasks);
180-
181-
$expected = array('Fixture' => null, 'DbConfig' => array('one', 'two'));
182-
$this->assertEquals($expected, Hash::normalize($this->Shell->tasks), 'Normalized results are wrong.');
183-
$this->assertEquals(array('Comment', 'Posts'), $this->Shell->uses, 'Merged models are wrong.');
184-
}
185-
186150
/**
187151
* testInitialize method
188152
*

0 commit comments

Comments
 (0)