From 41db1485aa41b5e43f17e0a58e1d2a693ec2ff40 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 6 Oct 2010 22:52:42 -0400 Subject: [PATCH] Updating test cases to use new objects. Preventing ConsoleOutput and ConsoleInput constructors from being run as it causes too many files open exceptions. --- .../console/console_error_handler.test.php | 2 +- cake/tests/cases/console/libs/acl.test.php | 5 +++- cake/tests/cases/console/libs/api.test.php | 5 +++- cake/tests/cases/console/libs/bake.test.php | 5 +++- .../cases/console/libs/command_list.test.php | 4 ++-- cake/tests/cases/console/libs/schema.test.php | 18 +++++++-------- cake/tests/cases/console/libs/shell.test.php | 6 ++--- .../console/libs/tasks/controller.test.php | 4 ++-- .../console/libs/tasks/db_config.test.php | 6 ++--- .../cases/console/libs/tasks/extract.test.php | 12 ++++++---- .../cases/console/libs/tasks/fixture.test.php | 8 +++---- .../cases/console/libs/tasks/model.test.php | 23 ++++++++++++------- .../cases/console/libs/tasks/plugin.test.php | 15 +++++++----- .../cases/console/libs/tasks/project.test.php | 9 ++++---- .../console/libs/tasks/template.test.php | 17 +++++++------- .../cases/console/libs/tasks/test.test.php | 17 +++++++------- .../cases/console/libs/tasks/view.test.php | 15 ++++++------ 17 files changed, 98 insertions(+), 73 deletions(-) diff --git a/cake/tests/cases/console/console_error_handler.test.php b/cake/tests/cases/console/console_error_handler.test.php index d1171d2b1..0a089f09f 100644 --- a/cake/tests/cases/console/console_error_handler.test.php +++ b/cake/tests/cases/console/console_error_handler.test.php @@ -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; } diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 94869be49..e8597ce22 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -49,6 +49,9 @@ class AclShellTest extends CakeTestCase { 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') @@ -56,7 +59,7 @@ class AclShellTest extends CakeTestCase { $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); diff --git a/cake/tests/cases/console/libs/api.test.php b/cake/tests/cases/console/libs/api.test.php index e4d5f5478..685ddb091 100644 --- a/cake/tests/cases/console/libs/api.test.php +++ b/cake/tests/cases/console/libs/api.test.php @@ -38,6 +38,9 @@ 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') @@ -45,7 +48,7 @@ class ApiShellTest extends CakeTestCase { $this->Shell = $this->getMock( 'ApiShell', array('in', 'out', 'createFile', 'hr', '_stop'), - array(&$this->Dispatcher) + array(&$this->Dispatcher, $out, $out, $in) ); } diff --git a/cake/tests/cases/console/libs/bake.test.php b/cake/tests/cases/console/libs/bake.test.php index acefbc732..9b546339f 100644 --- a/cake/tests/cases/console/libs/bake.test.php +++ b/cake/tests/cases/console/libs/bake.test.php @@ -50,6 +50,9 @@ 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') @@ -57,7 +60,7 @@ class BakeShellTest extends CakeTestCase { $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'); } diff --git a/cake/tests/cases/console/libs/command_list.test.php b/cake/tests/cases/console/libs/command_list.test.php index 0572d7616..486f3a88f 100644 --- a/cake/tests/cases/console/libs/command_list.test.php +++ b/cake/tests/cases/console/libs/command_list.test.php @@ -53,12 +53,12 @@ class CommandListTest extends CakeTestCase { 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) ); } diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index b59f87027..7d343dc9c 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -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 @@ class SchemaShellTest extends CakeTestCase { * * @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(); } /** diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index 6f12c46fb..fed9894bd 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -108,9 +108,9 @@ class ShellTest extends CakeTestCase { '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); } diff --git a/cake/tests/cases/console/libs/tasks/controller.test.php b/cake/tests/cases/console/libs/tasks/controller.test.php index 6c469a195..1e68acbd0 100644 --- a/cake/tests/cases/console/libs/tasks/controller.test.php +++ b/cake/tests/cases/console/libs/tasks/controller.test.php @@ -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) diff --git a/cake/tests/cases/console/libs/tasks/db_config.test.php b/cake/tests/cases/console/libs/tasks/db_config.test.php index 1ea686daf..a03660869 100644 --- a/cake/tests/cases/console/libs/tasks/db_config.test.php +++ b/cake/tests/cases/console/libs/tasks/db_config.test.php @@ -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 @@ class DbConfigTaskTest extends CakeTestCase { 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) diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index 2f7d08bfa..cd2393183 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -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 @@ class ExtractTaskTest extends CakeTestCase { * @return void */ public function tearDown() { - ClassRegistry::flush(); + parent::tearDown(); + unset($this->Task, $this->Dispatcher); } /** diff --git a/cake/tests/cases/console/libs/tasks/fixture.test.php b/cake/tests/cases/console/libs/tasks/fixture.test.php index 6e25291c2..7b8e82c01 100644 --- a/cake/tests/cases/console/libs/tasks/fixture.test.php +++ b/cake/tests/cases/console/libs/tasks/fixture.test.php @@ -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 @@ class FixtureTaskTest extends CakeTestCase { * @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); diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index f7cbcb2ac..33dd42a37 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -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 @@ class ModelTaskTest extends CakeTestCase { * @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 @@ class ModelTaskTest extends CakeTestCase { * @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; diff --git a/cake/tests/cases/console/libs/tasks/plugin.test.php b/cake/tests/cases/console/libs/tasks/plugin.test.php index cdaf78085..5fda7fda2 100644 --- a/cake/tests/cases/console/libs/tasks/plugin.test.php +++ b/cake/tests/cases/console/libs/tasks/plugin.test.php @@ -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 @@ class PluginTaskTest extends CakeTestCase { * @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)); diff --git a/cake/tests/cases/console/libs/tasks/project.test.php b/cake/tests/cases/console/libs/tasks/project.test.php index 0460071a5..855908ed4 100644 --- a/cake/tests/cases/console/libs/tasks/project.test.php +++ b/cake/tests/cases/console/libs/tasks/project.test.php @@ -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; diff --git a/cake/tests/cases/console/libs/tasks/template.test.php b/cake/tests/cases/console/libs/tasks/template.test.php index e0cbc652a..752af6d51 100644 --- a/cake/tests/cases/console/libs/tasks/template.test.php +++ b/cake/tests/cases/console/libs/tasks/template.test.php @@ -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 @@ class TemplateTaskTest extends CakeTestCase { * * @return void */ - public function teardown() { + public function tearDown() { + parent::tearDown(); unset($this->Task, $this->Dispatcher); - ClassRegistry::flush(); - App::build(); } /** diff --git a/cake/tests/cases/console/libs/tasks/test.test.php b/cake/tests/cases/console/libs/tasks/test.test.php index 513df3ba7..4508e82e1 100644 --- a/cake/tests/cases/console/libs/tasks/test.test.php +++ b/cake/tests/cases/console/libs/tasks/test.test.php @@ -239,16 +239,17 @@ 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); } /** @@ -256,9 +257,9 @@ class TestTaskTest extends CakeTestCase { * * @return void */ - public function teardown() { - parent::teardown(); - ClassRegistry::flush(); + public function tearDown() { + parent::tearDown(); + unset($this->Task, $this->Dispatcher); } /** diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index 4d062ed7c..c43b55a4e 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -222,16 +222,17 @@ class ViewTaskTest 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('ViewTask', array('in', 'err', 'createFile', '_stop'), - array(&$this->Dispatcher) + array(&$this->Dispatcher, $out, $out, $in) ); - $this->Task->Template = new TemplateTask($this->Dispatcher); - $this->Task->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher)); - $this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher)); + $this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in); + $this->Task->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher, $out, $out, $in)); + $this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher, $out, $out, $in)); $this->Dispatcher->shellPaths = App::path('shells'); $this->Task->path = TMP;