Skip to content

Commit

Permalink
Updating test cases to use new objects.
Browse files Browse the repository at this point in the history
Preventing ConsoleOutput and ConsoleInput constructors from being run as it causes too many files open exceptions.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 73ad304 commit 41db148
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 73 deletions.
2 changes: 1 addition & 1 deletion cake/tests/cases/console/console_error_handler.test.php
Expand Up @@ -33,7 +33,7 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
*/
function getErrorHandler($exception) {
$error = new ConsoleErrorHandler($exception);
$error->stderr = $this->getMock('ConsoleOutput');
$error->stderr = $this->getMock('ConsoleOutput', array(), array(), '', false);
return $error;
}

Expand Down
5 changes: 4 additions & 1 deletion cake/tests/cases/console/libs/acl.test.php
Expand Up @@ -49,14 +49,17 @@ public function setUp() {
Configure::write('Acl.database', 'test');
Configure::write('Acl.classname', 'DbAcl');

$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('_stop', '_initEnvironment', 'dispatch')
);
$this->Task = $this->getMock(
'AclShell',
array('in', 'out', 'hr', 'createFile', 'error', 'err'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$collection = new ComponentCollection();
$this->Task->Acl = new AclComponent($collection);
Expand Down
5 changes: 4 additions & 1 deletion cake/tests/cases/console/libs/api.test.php
Expand Up @@ -38,14 +38,17 @@ class ApiShellTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('_stop', '_initEnvironment', 'dispatch')
);
$this->Shell = $this->getMock(
'ApiShell',
array('in', 'out', 'createFile', 'hr', '_stop'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
}

Expand Down
5 changes: 4 additions & 1 deletion cake/tests/cases/console/libs/bake.test.php
Expand Up @@ -50,14 +50,17 @@ class BakeShellTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('_stop', '_initEnvironment')
);
$this->Shell = $this->getMock(
'BakeShell',
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Shell->Dispatch->shellPaths = App::path('shells');
}
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/console/libs/command_list.test.php
Expand Up @@ -53,12 +53,12 @@ public function setUp() {
array('_stop', '_initEnvironment', 'dispatch')
);
$out = new TestStringOutput();
$in = $this->getMock('ConsoleInput');
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Shell = $this->getMock(
'CommandListShell',
array('in', '_stop', 'clear'),
array(&$this->Dispatcher, $out, null, $in)
array(&$this->Dispatcher, $out, $out, $in)
);
}

Expand Down
18 changes: 9 additions & 9 deletions cake/tests/cases/console/libs/schema.test.php
Expand Up @@ -108,15 +108,16 @@ class SchemaShellTest extends CakeTestCase {
*
* @return void
*/
public function setup() {
$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
);
public function setUp() {
parent::setUp();

$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Shell = $this->getMock(
'SchemaShell',
array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
}

Expand All @@ -125,13 +126,12 @@ public function setup() {
*
* @return void
*/
public function teardown() {
ClassRegistry::flush();
public function tearDown() {
parent::tearDown();
if (!empty($this->file) && $this->file instanceof File) {
$this->file->delete();
unset($this->file);
}
App::build();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions cake/tests/cases/console/libs/shell.test.php
Expand Up @@ -108,9 +108,9 @@ public function setUp() {
'ShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
);
$output = $this->getMock('ConsoleOutput');
$error = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');
$output = $this->getMock('ConsoleOutput', array(), array(), '', false);
$error = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Shell =& new TestShell($this->Dispatcher, $output, $error, $in);
}

Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -68,8 +68,8 @@ class ControllerTaskTest extends CakeTestCase {
*/
public function setUp() {
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task = $this->getMock('ControllerTask',
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher, $out, $out, $in)
Expand Down
6 changes: 3 additions & 3 deletions cake/tests/cases/console/libs/tasks/db_config.test.php
Expand Up @@ -60,8 +60,8 @@ class DbConfigTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('DbConfigTask',
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testInitialize() {
public function testExecuteIntoInteractive() {
$this->Task->initialize();

$out = $this->getMock('ConsoleOutput');
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$this->Task = $this->getMock(
'DbConfigTask',
array('in', '_stop', 'createFile'), array(&$this->Dispatcher, $out, $out)
Expand Down
12 changes: 7 additions & 5 deletions cake/tests/cases/console/libs/tasks/extract.test.php
Expand Up @@ -39,10 +39,11 @@ class ExtractTaskTest extends CakeTestCase {
* @return void
*/
public function setUp() {
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$this->Task =& new ExtractTask($this->Dispatcher);
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = new ExtractTask($this->Dispatcher, $out, $out, $in);
}

/**
Expand All @@ -51,7 +52,8 @@ public function setUp() {
* @return void
*/
public function tearDown() {
ClassRegistry::flush();
parent::tearDown();
unset($this->Task, $this->Dispatcher);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -46,8 +46,8 @@ class FixtureTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('FixtureTask',
Expand Down Expand Up @@ -79,8 +79,8 @@ public function tearDown() {
* @return void
*/
public function testConstruct() {
$out = $this->getMock('ConsoleOutput');
$in = $this->getMock('ConsoleInput');
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher->params['working'] = DS . 'my' . DS . 'path';
$Task = new FixtureTask($this->Dispatcher, $out, $out, $in);
Expand Down
23 changes: 15 additions & 8 deletions cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -49,12 +49,13 @@ class ModelTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('ModelTask',
array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->_setupOtherMocks();
}
Expand All @@ -65,9 +66,12 @@ public function setUp() {
* @return void
*/
protected function _useMockedOut() {
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Task = $this->getMock('ModelTask',
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->_setupOtherMocks();
}
Expand All @@ -78,9 +82,12 @@ protected function _useMockedOut() {
* @return void
*/
protected function _setupOtherMocks() {
$this->Task->Fixture = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher));
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher));
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Task->Fixture = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->Template =& new TemplateTask($this->Task->Dispatch, $out, $out, $in);

$this->Task->name = 'ModelTask';
$this->Task->interactive = true;
Expand Down
15 changes: 9 additions & 6 deletions cake/tests/cases/console/libs/tasks/plugin.test.php
Expand Up @@ -41,13 +41,13 @@ class PluginTaskTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('PluginTask',
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher)
array('in', 'err', 'createFile', '_stop', 'clear'),
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->path = TMP . 'tests' . DS;

Expand Down Expand Up @@ -221,7 +221,10 @@ public function testExecuteWithOneArg() {
* @return void
*/
public function testExecuteWithTwoArgs() {
$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher, $out, $out, $in));

$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));

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

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment', 'clear'));
$this->Task = $this->getMock('ProjectTask',
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP . 'tests' . DS;
Expand Down
17 changes: 9 additions & 8 deletions cake/tests/cases/console/libs/tasks/template.test.php
Expand Up @@ -39,12 +39,14 @@ class TemplateTaskTest extends CakeTestCase {
* @return void
*/
public function setup() {
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
parent::setUp();
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('TemplateTask',
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher)
array('in', 'err', 'createFile', '_stop', 'clear'),
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Dispatch->shellPaths = App::path('shells');
}
Expand All @@ -54,10 +56,9 @@ public function setup() {
*
* @return void
*/
public function teardown() {
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatcher);
ClassRegistry::flush();
App::build();
}

/**
Expand Down
17 changes: 9 additions & 8 deletions cake/tests/cases/console/libs/tasks/test.test.php
Expand Up @@ -239,26 +239,27 @@ class TestTaskTest extends CakeTestCase {
*/
public function setup() {
parent::setup();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);

$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
$this->Task = $this->getMock('TestTask',
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array(&$this->Dispatcher)
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->name = 'TestTask';
$this->Task->Template = new TemplateTask($this->Dispatcher);
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
}

/**
* endTest method
*
* @return void
*/
public function teardown() {
parent::teardown();
ClassRegistry::flush();
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatcher);
}

/**
Expand Down

0 comments on commit 41db148

Please sign in to comment.