Skip to content
Permalink
Browse files

Updating test cases to use new objects.

Preventing ConsoleOutput and ConsoleInput constructors from being run as it causes too many files open exceptions.
  • Loading branch information...
markstory committed Oct 7, 2010
1 parent 73ad304 commit 41db1485aa41b5e43f17e0a58e1d2a693ec2ff40
@@ -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;
}
@@ -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);
@@ -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)
);
}
@@ -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');
}
@@ -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)
);
}
@@ -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)
);
}
@@ -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();
}
/**
@@ -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);
}
@@ -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)
@@ -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',
@@ -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)
@@ -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);
}
/**
@@ -51,7 +52,8 @@ public function setUp() {
* @return void
*/
public function tearDown() {
ClassRegistry::flush();
parent::tearDown();
unset($this->Task, $this->Dispatcher);
}
/**
@@ -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',
@@ -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);
@@ -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();
}
@@ -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();
}
@@ -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;
@@ -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;
@@ -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));
@@ -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;
@@ -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');
}
@@ -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();
}
/**
@@ -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);
}
/**
Oops, something went wrong.

0 comments on commit 41db148

Please sign in to comment.
You can’t perform that action at this time.