Skip to content
Permalink
Browse files

Moving common setup and teardown functionality in to CakeTestCase.

Removing repeated setup/teardown logic from test cases.
Switching tests to use setup/teardown instead of startTest/endTest.
  • Loading branch information...
markstory committed Sep 26, 2010
1 parent 24dd0af commit 92b57d81ee1c05ac0a226ff7e9f85f8f765b07b0
Showing with 198 additions and 269 deletions.
  1. +1 −9 cake/tests/cases/console/cake.test.php
  2. +3 −15 cake/tests/cases/console/libs/acl.test.php
  3. +3 −11 cake/tests/cases/console/libs/api.test.php
  4. +6 −4 cake/tests/cases/console/libs/bake.test.php
  5. +5 −4 cake/tests/cases/console/libs/tasks/db_config.test.php
  6. +6 −5 cake/tests/cases/console/libs/tasks/fixture.test.php
  7. +6 −5 cake/tests/cases/console/libs/tasks/model.test.php
  8. +14 −31 cake/tests/cases/console/libs/tasks/plugin.test.php
  9. +6 −5 cake/tests/cases/console/libs/tasks/project.test.php
  10. +7 −8 cake/tests/cases/console/libs/tasks/view.test.php
  11. +2 −1 cake/tests/cases/libs/cake_log.test.php
  12. +5 −5 cake/tests/cases/libs/cake_request.test.php
  13. +0 −1 cake/tests/cases/libs/cake_response.test.php
  14. +8 −10 cake/tests/cases/libs/controller/components/acl.test.php
  15. +4 −12 cake/tests/cases/libs/controller/components/auth.test.php
  16. +6 −5 cake/tests/cases/libs/controller/components/security.test.php
  17. +12 −13 cake/tests/cases/libs/controller/scaffold.test.php
  18. +3 −4 cake/tests/cases/libs/model/cake_schema.test.php
  19. +6 −8 cake/tests/cases/libs/model/datasources/dbo_source.test.php
  20. +3 −13 cake/tests/cases/libs/route/cake_route.test.php
  21. +3 −13 cake/tests/cases/libs/route/plugin_short_route.test.php
  22. +1 −11 cake/tests/cases/libs/router.test.php
  23. +4 −2 cake/tests/cases/libs/session/cache_session.test.php
  24. +1 −0 cake/tests/cases/libs/test_manager.test.php
  25. +7 −36 cake/tests/cases/libs/view/helpers/html.test.php
  26. +6 −4 cake/tests/cases/libs/view/helpers/jquery_engine.test.php
  27. +6 −7 cake/tests/cases/libs/view/helpers/js.test.php
  28. +9 −5 cake/tests/cases/libs/view/helpers/mootools_engine.test.php
  29. +4 −4 cake/tests/cases/libs/view/helpers/number.test.php
  30. +7 −5 cake/tests/cases/libs/view/helpers/prototype_engine.test.php
  31. +5 −6 cake/tests/cases/libs/view/media.test.php
  32. +3 −6 cake/tests/cases/libs/view/view.test.php
  33. +2 −1 cake/tests/cases/libs/xml.test.php
  34. +34 −0 cake/tests/lib/cake_test_case.php
@@ -165,6 +165,7 @@ class ShellDispatcherTest extends CakeTestCase {
* @return void
*/
public function setUp() {
parent::setUp();
App::build(array(
'plugins' => array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
@@ -176,15 +177,6 @@ public function setUp() {
), true);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
App::build();
}
/**
* testParseParams method
*
@@ -51,13 +51,12 @@ class AclShellTest extends CakeTestCase {
public $fixtures = array('core.aco', 'core.aro', 'core.aros_aco');
/**
* startTest method
* setup method
*
* @return void
*/
public function startTest() {
$this->_aclDb = Configure::read('Acl.database');
$this->_aclClass = Configure::read('Acl.classname');
public function setUp() {
parent::setUp();
Configure::write('Acl.database', 'test');
Configure::write('Acl.classname', 'DbAcl');
@@ -77,17 +76,6 @@ public function startTest() {
$this->Task->params['datasource'] = 'test';
}
/**
* endTest method
*
* @return void
*/
public function endTest() {
ClassRegistry::flush();
Configure::write('Acl.database', $this->_aclDb);
Configure::write('Acl.classname', $this->_aclClass);
}
/**
* test that model.foreign_key output works when looking at acl rows
*
@@ -43,11 +43,12 @@
class ApiShellTest extends CakeTestCase {
/**
* startTest method
* setUp method
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'dispatch', 'clear')
@@ -59,15 +60,6 @@ public function startTest() {
);
}
/**
* tearDown method
*
* @return void
*/
public function endTest() {
ClassRegistry::flush();
}
/**
* Test that method names are detected properly including those with no arguments.
*
@@ -54,11 +54,12 @@ class BakeShellTest extends CakeTestCase {
public $fixtures = array('core.user');
/**
* start test
* setup test
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
@@ -72,11 +73,12 @@ public function startTest() {
}
/**
* endTest method
* teardown method
*
* @return void
*/
public function endTest() {
public function tearDown() {
parent::tearDown();
unset($this->Dispatch, $this->Shell);
}
@@ -64,11 +64,12 @@ class TEST_DATABASE_CONFIG {
class DbConfigTaskTest extends CakeTestCase {
/**
* startTest method
* setup method
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
@@ -87,9 +88,9 @@ public function startTest() {
*
* @return void
*/
public function endTest() {
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatcher);
ClassRegistry::flush();
}
/**
@@ -50,11 +50,12 @@ class FixtureTaskTest extends CakeTestCase {
public $fixtures = array('core.article', 'core.comment', 'core.datatype', 'core.binary_test');
/**
* startTest method
* setUp method
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
@@ -72,13 +73,13 @@ public function startTest() {
}
/**
* endTest method
* tearDown method
*
* @return void
*/
public function endTest() {
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatcher);
ClassRegistry::flush();
}
/**
@@ -53,11 +53,12 @@ class ModelTaskTest extends CakeTestCase {
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag', 'core.category_thread');
/**
* starTest method
* setUp method
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
@@ -97,13 +98,13 @@ protected function _setupOtherMocks() {
}
/**
* endTest method
* teardown method
*
* @return void
*/
public function endTest() {
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatcher);
ClassRegistry::flush();
}
/**
@@ -44,16 +44,14 @@
*/
class PluginTaskTest extends CakeTestCase {
public static $_paths = array();
public static $_testPath = array();
/**
* startTest method
* setup method
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
@@ -62,35 +60,20 @@ public function startTest() {
array(&$this->Dispatcher)
);
$this->Task->path = TMP . 'tests' . DS;
}
/**
* startCase methods
*
* @return void
*/
public static function setUpBeforeClass() {
self::$_paths = $paths = App::path('plugins');
self::$_testPath = array_push($paths, TMP . 'tests' . DS);
$this->_paths = $paths = App::path('plugins');
$this->_testPath = array_push($paths, TMP . 'tests' . DS);
App::build(array('plugins' => $paths));
}
/**
* endCase
*
* @return void
*/
public static function tearDownAfterClass() {
App::build(array('plugins' => self::$_paths));
}
/**
* endTest method
* teardown
*
* @return void
*/
public function endTest() {
ClassRegistry::flush();
public function tearDown() {
parent::tearDown();
App::build(array('plugins' => $this->_paths));
}
/**
@@ -99,7 +82,7 @@ public function endTest() {
* @return void
*/
public function testBakeFoldersAndFiles() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(self::$_testPath));
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
$path = $this->Task->path . 'bake_test_plugin';
@@ -219,7 +202,7 @@ public function testExecuteWithNoArgs() {
*/
public function testExecuteWithOneArg() {
$this->Task->expects($this->at(0))->method('in')
->will($this->returnValue(self::$_testPath));
->will($this->returnValue($this->_testPath));
$this->Task->expects($this->at(1))->method('in')
->will($this->returnValue('y'));
@@ -250,7 +233,7 @@ public function testExecuteWithOneArg() {
public function testExecuteWithTwoArgs() {
$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(self::$_testPath));
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));
$this->Task->Model->expects($this->once())->method('loadTasks');
$this->Task->Model->expects($this->once())->method('execute');
@@ -45,11 +45,12 @@
class ProjectTaskTest extends CakeTestCase {
/**
* startTest method
* setup method
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
@@ -62,12 +63,12 @@ public function startTest() {
}
/**
* endTest method
* teardown method
*
* @return void
*/
public function endTest() {
ClassRegistry::flush();
public function tearDown() {
parent::tearDown();
$Folder = new Folder($this->Task->path . 'bake_test_app');
$Folder->delete();
@@ -224,13 +224,14 @@ class ViewTaskTest extends CakeTestCase {
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
/**
* startTest method
* setUp method
*
* Ensure that the default theme is used
*
* @return void
*/
public function startTest() {
public function setUp() {
parent::setUp();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear'
));
@@ -245,18 +246,16 @@ public function startTest() {
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP;
$this->Task->Template->params['theme'] = 'default';
$this->_routing = Configure::read('Routing');
}
/**
* endTest method
* tearDown method
*
* @return void
*/
public function endTest() {
ClassRegistry::flush();
Configure::write('Routing', $this->_routing);
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatch);
}
/**
@@ -33,7 +33,8 @@ class CakeLogTest extends CakeTestCase {
*
* @return void
*/
function startTest() {
function setUp() {
parent::setUp();
$streams = CakeLog::configured();
foreach ($streams as $stream) {
CakeLog::drop($stream);
Oops, something went wrong.

0 comments on commit 92b57d8

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