Skip to content

Commit

Permalink
Update Shell to use MergeVariablesTrait.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 14, 2012
1 parent f108089 commit fb37e21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 43 deletions.
13 changes: 6 additions & 7 deletions lib/Cake/Console/Shell.php
Expand Up @@ -27,6 +27,7 @@
use Cake\Utility\ClassRegistry;
use Cake\Utility\File;
use Cake\Utility\Inflector;
use Cake\Utility\MergeVariablesTrait;
use Cake\Utility\String;

/**
Expand All @@ -36,6 +37,7 @@
*/
class Shell extends Object {

use MergeVariablesTrait;
/**
* Output constants for making verbose and quiet shells.
*/
Expand Down Expand Up @@ -179,13 +181,10 @@ public function __construct($stdout = null, $stderr = null, $stdin = null) {
$this->stdin = new ConsoleInput('php://stdin');
}
$this->_useLogger();
$parent = get_parent_class($this);
if ($this->tasks !== null && $this->tasks !== false) {
$this->_mergeVars(array('tasks'), $parent, true);
}
if ($this->uses !== null && $this->uses !== false) {
$this->_mergeVars(array('uses'), $parent, false);
}
$this->_mergeVars(
['tasks', 'uses'],
['associative' => ['tasks']]
);
}

/**
Expand Down
36 changes: 0 additions & 36 deletions lib/Cake/Test/TestCase/Console/ShellTest.php
Expand Up @@ -74,29 +74,12 @@ public function log_something() {
}
//@codingStandardsIgnoreEnd

public function mergeVars($properties, $class, $normalize = true) {
return $this->_mergeVars($properties, $class, $normalize);
}

public function useLogger($enable = true) {
$this->_useLogger($enable);
}

}

/**
* Class for testing merging vars
*
* @package Cake.Test.Case.Console.Command
*/
class TestMergeShell extends Shell {

public $tasks = array('DbConfig', 'Fixture');

public $uses = array('Comment');

}

/**
* TestAppleTask class
*
Expand Down Expand Up @@ -164,25 +147,6 @@ public function testConstruct() {
$this->assertInstanceOf('Cake\Console\ConsoleOutput', $this->Shell->stderr);
}

/**
* test merging vars
*
* @return void
*/
public function testMergeVars() {
$this->Shell->tasks = array('DbConfig' => array('one', 'two'));
$this->Shell->uses = array('Posts');
$this->Shell->mergeVars(array('tasks'), __NAMESPACE__ . '\TestMergeShell');
$this->Shell->mergeVars(array('uses'), __NAMESPACE__ . '\TestMergeShell', false);

$expected = array('DbConfig' => null, 'Fixture' => null, 'DbConfig' => array('one', 'two'));
$this->assertEquals($expected, $this->Shell->tasks);

$expected = array('Fixture' => null, 'DbConfig' => array('one', 'two'));
$this->assertEquals($expected, Hash::normalize($this->Shell->tasks), 'Normalized results are wrong.');
$this->assertEquals(array('Comment', 'Posts'), $this->Shell->uses, 'Merged models are wrong.');
}

/**
* testInitialize method
*
Expand Down

0 comments on commit fb37e21

Please sign in to comment.