Skip to content

Commit

Permalink
Fixing more console tests to use new internals.
Browse files Browse the repository at this point in the history
Making TaskCollection pass the stdout, stdin, stderr to Tasks they create.  This allows for more flexible dependency injection and makes testing easier.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent a302343 commit 73ad304
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
4 changes: 3 additions & 1 deletion cake/console/libs/task_collection.php
Expand Up @@ -60,7 +60,9 @@ public function load($task, $settings = array(), $enable = true) {
}
}

$this->_loaded[$name] = new $taskClass($this->_Shell);
$this->_loaded[$name] = new $taskClass(
$this->_Shell, $this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin
);
if ($enable === true) {
$this->_enabled[] = $name;
}
Expand Down
4 changes: 2 additions & 2 deletions cake/console/libs/tasks/fixture.php
Expand Up @@ -54,8 +54,8 @@ class FixtureTask extends BakeTask {
* Override initialize
*
*/
public function __construct(&$dispatch) {
parent::__construct($dispatch);
public function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin = null) {
parent::__construct($dispatch, $stdout, $stderr, $stdin);
$this->path = $this->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
}

Expand Down
14 changes: 7 additions & 7 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -67,12 +67,12 @@ class ControllerTaskTest extends CakeTestCase {
* @return void
*/
public function setUp() {
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');
$this->Task = $this->getMock('ControllerTask',
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->name = 'ControllerTask';
$this->Task->Dispatch->shellPaths = App::path('shells');
Expand All @@ -81,13 +81,13 @@ public function setUp() {

$this->Task->Model = $this->getMock('ModelTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Project = $this->getMock('ProjectTask',
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher));
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher, $out, $out, $in));
}

/**
Expand Down
16 changes: 11 additions & 5 deletions cake/tests/cases/console/libs/tasks/db_config.test.php
Expand Up @@ -60,12 +60,13 @@ class DbConfigTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('DbConfigTask',
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest', '_verify'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Dispatch->shellPaths = App::path('shells');

Expand Down Expand Up @@ -114,7 +115,12 @@ public function testInitialize() {
*/
public function testExecuteIntoInteractive() {
$this->Task->initialize();
$this->Task = $this->getMock('DbConfigTask', array('in', '_stop', 'createFile'), array(&$this->Dispatcher));

$out = $this->getMock('ConsoleOutput');
$this->Task = $this->getMock(
'DbConfigTask',
array('in', '_stop', 'createFile'), array(&$this->Dispatcher, $out, $out)
);

$this->Task->expects($this->once())->method('_stop');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('default')); //name
Expand Down
28 changes: 14 additions & 14 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -19,10 +19,6 @@
*/
App::import('Shell', 'Shell', false);

if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
}

require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
Expand Down Expand Up @@ -50,18 +46,19 @@ class FixtureTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('FixtureTask',
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher)
array('in', 'err', 'createFile', '_stop', 'clear'),
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Model = $this->getMock('Shell',
array('in', 'out', 'erro', 'createFile', 'getName', 'getTable', 'listAll'),
array(&$this->Dispatcher)
array('in', 'out', 'error', 'createFile', 'getName', 'getTable', 'listAll'),
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Template =& new TemplateTask($this->Dispatcher);
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template->initialize();
}
Expand All @@ -82,8 +79,11 @@ public function tearDown() {
* @return void
*/
public function testConstruct() {
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');

$this->Dispatcher->params['working'] = DS . 'my' . DS . 'path';
$Task = new FixtureTask($this->Dispatcher);
$Task = new FixtureTask($this->Dispatcher, $out, $out, $in);

$expected = DS . 'my' . DS . 'path' . DS . 'tests' . DS . 'fixtures' . DS;
$this->assertEqual($Task->path, $expected);
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testImportOptionsTable() {
*
* @return void
*/
public function testImportRecordsFromDatabaseWithConditions() {
public function testImportRecordsFromDatabaseWithConditionsPoo() {
$this->Task->interactive = true;
$this->Task->expects($this->at(0))->method('in')
->will($this->returnValue('WHERE 1=1 LIMIT 10'));
Expand Down

0 comments on commit 73ad304

Please sign in to comment.