From 92b57d81ee1c05ac0a226ff7e9f85f8f765b07b0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 25 Sep 2010 21:36:49 -0400 Subject: [PATCH] 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. --- cake/tests/cases/console/cake.test.php | 10 +---- cake/tests/cases/console/libs/acl.test.php | 18 ++------ cake/tests/cases/console/libs/api.test.php | 14 ++---- cake/tests/cases/console/libs/bake.test.php | 10 +++-- .../console/libs/tasks/db_config.test.php | 9 ++-- .../cases/console/libs/tasks/fixture.test.php | 11 ++--- .../cases/console/libs/tasks/model.test.php | 11 ++--- .../cases/console/libs/tasks/plugin.test.php | 45 ++++++------------- .../cases/console/libs/tasks/project.test.php | 11 ++--- .../cases/console/libs/tasks/view.test.php | 15 +++---- cake/tests/cases/libs/cake_log.test.php | 3 +- cake/tests/cases/libs/cake_request.test.php | 10 ++--- cake/tests/cases/libs/cake_response.test.php | 1 - .../libs/controller/components/acl.test.php | 18 ++++---- .../libs/controller/components/auth.test.php | 16 ++----- .../controller/components/security.test.php | 11 ++--- .../cases/libs/controller/scaffold.test.php | 25 +++++------ .../cases/libs/model/cake_schema.test.php | 7 ++- .../model/datasources/dbo_source.test.php | 14 +++--- .../cases/libs/route/cake_route.test.php | 16 ++----- .../libs/route/plugin_short_route.test.php | 16 ++----- cake/tests/cases/libs/router.test.php | 12 +---- .../cases/libs/session/cache_session.test.php | 6 ++- cake/tests/cases/libs/test_manager.test.php | 1 + .../cases/libs/view/helpers/html.test.php | 43 +++--------------- .../libs/view/helpers/jquery_engine.test.php | 10 +++-- .../tests/cases/libs/view/helpers/js.test.php | 13 +++--- .../view/helpers/mootools_engine.test.php | 14 +++--- .../cases/libs/view/helpers/number.test.php | 8 ++-- .../view/helpers/prototype_engine.test.php | 12 ++--- cake/tests/cases/libs/view/media.test.php | 11 +++-- cake/tests/cases/libs/view/view.test.php | 9 ++-- cake/tests/cases/libs/xml.test.php | 3 +- cake/tests/lib/cake_test_case.php | 34 ++++++++++++++ 34 files changed, 198 insertions(+), 269 deletions(-) diff --git a/cake/tests/cases/console/cake.test.php b/cake/tests/cases/console/cake.test.php index 8ed92c6e4..aa0deee61 100644 --- a/cake/tests/cases/console/cake.test.php +++ b/cake/tests/cases/console/cake.test.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 @@ class ShellDispatcherTest extends CakeTestCase { ), true); } -/** - * tearDown method - * - * @return void - */ - public function tearDown() { - App::build(); - } - /** * testParseParams method * diff --git a/cake/tests/cases/console/libs/acl.test.php b/cake/tests/cases/console/libs/acl.test.php index 382c4a9f7..259c0c26d 100644 --- a/cake/tests/cases/console/libs/acl.test.php +++ b/cake/tests/cases/console/libs/acl.test.php @@ -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 @@ class AclShellTest extends CakeTestCase { $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 * diff --git a/cake/tests/cases/console/libs/api.test.php b/cake/tests/cases/console/libs/api.test.php index 90df32575..39fac8268 100644 --- a/cake/tests/cases/console/libs/api.test.php +++ b/cake/tests/cases/console/libs/api.test.php @@ -43,11 +43,12 @@ if (!class_exists('ApiShell')) { 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 @@ class ApiShellTest extends CakeTestCase { ); } -/** - * tearDown method - * - * @return void - */ - public function endTest() { - ClassRegistry::flush(); - } - /** * Test that method names are detected properly including those with no arguments. * diff --git a/cake/tests/cases/console/libs/bake.test.php b/cake/tests/cases/console/libs/bake.test.php index cd6d49767..eb29b9ca2 100644 --- a/cake/tests/cases/console/libs/bake.test.php +++ b/cake/tests/cases/console/libs/bake.test.php @@ -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 @@ class BakeShellTest extends CakeTestCase { } /** - * endTest method + * teardown method * * @return void */ - public function endTest() { + public function tearDown() { + parent::tearDown(); unset($this->Dispatch, $this->Shell); } 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 eec7324f9..b4271bb4b 100644 --- a/cake/tests/cases/console/libs/tasks/db_config.test.php +++ b/cake/tests/cases/console/libs/tasks/db_config.test.php @@ -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 @@ class DbConfigTaskTest extends CakeTestCase { * * @return void */ - public function endTest() { + public function tearDown() { + parent::tearDown(); unset($this->Task, $this->Dispatcher); - ClassRegistry::flush(); } /** diff --git a/cake/tests/cases/console/libs/tasks/fixture.test.php b/cake/tests/cases/console/libs/tasks/fixture.test.php index c396cd60c..aebacaede 100644 --- a/cake/tests/cases/console/libs/tasks/fixture.test.php +++ b/cake/tests/cases/console/libs/tasks/fixture.test.php @@ -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 @@ class FixtureTaskTest extends CakeTestCase { } /** - * endTest method + * tearDown method * * @return void */ - public function endTest() { + public function tearDown() { + parent::tearDown(); unset($this->Task, $this->Dispatcher); - ClassRegistry::flush(); } /** diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index 88255dcce..237a52dce 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -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 @@ class ModelTaskTest extends CakeTestCase { } /** - * endTest method + * teardown method * * @return void */ - public function endTest() { + public function tearDown() { + parent::tearDown(); unset($this->Task, $this->Dispatcher); - ClassRegistry::flush(); } /** diff --git a/cake/tests/cases/console/libs/tasks/plugin.test.php b/cake/tests/cases/console/libs/tasks/plugin.test.php index b2e6b3af9..e79541c41 100644 --- a/cake/tests/cases/console/libs/tasks/plugin.test.php +++ b/cake/tests/cases/console/libs/tasks/plugin.test.php @@ -44,16 +44,14 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php'; */ 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 @@ class PluginTaskTest extends CakeTestCase { 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 + * teardown * * @return void */ - public static function tearDownAfterClass() { - App::build(array('plugins' => self::$_paths)); - } - -/** - * endTest method - * - * @return void - */ - public function endTest() { - ClassRegistry::flush(); + public function tearDown() { + parent::tearDown(); + App::build(array('plugins' => $this->_paths)); } /** @@ -99,7 +82,7 @@ class PluginTaskTest extends CakeTestCase { * @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 @@ class PluginTaskTest extends CakeTestCase { */ 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 @@ class PluginTaskTest extends CakeTestCase { 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'); diff --git a/cake/tests/cases/console/libs/tasks/project.test.php b/cake/tests/cases/console/libs/tasks/project.test.php index d4a98b7ab..67cb1c671 100644 --- a/cake/tests/cases/console/libs/tasks/project.test.php +++ b/cake/tests/cases/console/libs/tasks/project.test.php @@ -45,11 +45,12 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php' 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 @@ class ProjectTaskTest extends CakeTestCase { } /** - * 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(); diff --git a/cake/tests/cases/console/libs/tasks/view.test.php b/cake/tests/cases/console/libs/tasks/view.test.php index 8b118e25d..9d25ba87d 100644 --- a/cake/tests/cases/console/libs/tasks/view.test.php +++ b/cake/tests/cases/console/libs/tasks/view.test.php @@ -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 @@ class ViewTaskTest extends CakeTestCase { $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); } /** diff --git a/cake/tests/cases/libs/cake_log.test.php b/cake/tests/cases/libs/cake_log.test.php index 12b787426..eaa1f9337 100644 --- a/cake/tests/cases/libs/cake_log.test.php +++ b/cake/tests/cases/libs/cake_log.test.php @@ -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); diff --git a/cake/tests/cases/libs/cake_request.test.php b/cake/tests/cases/libs/cake_request.test.php index c57f831e4..80c8dafaf 100644 --- a/cake/tests/cases/libs/cake_request.test.php +++ b/cake/tests/cases/libs/cake_request.test.php @@ -28,25 +28,25 @@ class CakeRequestTestCase extends CakeTestCase { * * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $this->_server = $_SERVER; $this->_get = $_GET; $this->_post = $_POST; $this->_files = $_FILES; - $this->_app = Configure::read('App'); } /** - * end test + * tearDown * * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); $_SERVER = $this->_server; $_GET = $this->_get; $_POST = $this->_post; $_FILES = $this->_files; - Configure::write('App', $this->_app); } /** diff --git a/cake/tests/cases/libs/cake_response.test.php b/cake/tests/cases/libs/cake_response.test.php index 80c2a6a76..97a60e653 100644 --- a/cake/tests/cases/libs/cake_response.test.php +++ b/cake/tests/cases/libs/cake_response.test.php @@ -4,7 +4,6 @@ App::import('Core', 'CakeResponse'); class CakeResponseTestCase extends CakeTestCase { - /** * Tests the request object constructor * diff --git a/cake/tests/cases/libs/controller/components/acl.test.php b/cake/tests/cases/libs/controller/components/acl.test.php index 0be496c15..6d1ae1943 100644 --- a/cake/tests/cases/libs/controller/components/acl.test.php +++ b/cake/tests/cases/libs/controller/components/acl.test.php @@ -189,12 +189,12 @@ class DbAclTwoTest extends DbAcl { */ class AclComponentTest extends CakeTestCase { /** - * startTest method + * setUp method * - * @access public * @return void */ function setUp() { + parent::setUp(); if (!class_exists('MockAclImplementation', false)) { $this->getMock('AclInterface', array(), array(), 'MockAclImplementation'); } @@ -206,10 +206,10 @@ class AclComponentTest extends CakeTestCase { /** * tearDown method * - * @access public * @return void */ function tearDown() { + parent::tearDown(); unset($this->Acl); } @@ -347,14 +347,12 @@ class DbAclTest extends CakeTestCase { public $fixtures = array('core.aro_two', 'core.aco_two', 'core.aros_aco_two'); /** - * startTest method + * setUp method * - * @access public * @return void */ - function startTest() { - $this->_settings = Configure::read('Acl'); - + function setUp() { + parent::setUp(); Configure::write('Acl.classname', 'DbAclTwoTest'); Configure::write('Acl.database', 'test'); $Collection = new ComponentCollection(); @@ -367,9 +365,9 @@ class DbAclTest extends CakeTestCase { * @access public * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Acl); - Configure::write('Acl', $this->_settings); } /** diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 65074ec05..623c93ad0 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -473,21 +473,19 @@ class AuthTest extends CakeTestCase { public $initialized = false; /** - * startTest method + * setUp method * * @access public * @return void */ function setUp() { + parent::setUp(); $this->_server = $_SERVER; $this->_env = $_ENV; - $this->_securitySalt = Configure::read('Security.salt'); - $this->_securityCipher = Configure::read('Security.cipherSeed'); Configure::write('Security.salt', 'YJfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi'); Configure::write('Security.cipherSeed', 770011223369876); - $this->_acl = Configure::read('Acl'); Configure::write('Acl.database', 'test'); Configure::write('Acl.classname', 'DbAcl'); @@ -505,27 +503,21 @@ class AuthTest extends CakeTestCase { $this->Controller->Session->delete('Auth'); $this->Controller->Session->delete('Message.auth'); - Router::reload(); - $this->initialized = true; } /** - * endTest method + * tearDown method * - * @access public * @return void */ function tearDown() { + parent::tearDown(); $_SERVER = $this->_server; $_ENV = $this->_env; - Configure::write('Acl', $this->_acl); - Configure::write('Security.salt', $this->_securitySalt); - Configure::write('Security.cipherSeed', $this->_securityCipher); $this->Controller->Session->delete('Auth'); $this->Controller->Session->delete('Message.auth'); - ClassRegistry::flush(); unset($this->Controller, $this->AuthUser); } diff --git a/cake/tests/cases/libs/controller/components/security.test.php b/cake/tests/cases/libs/controller/components/security.test.php index fd6767950..b6b76cfbd 100644 --- a/cake/tests/cases/libs/controller/components/security.test.php +++ b/cake/tests/cases/libs/controller/components/security.test.php @@ -143,25 +143,26 @@ class SecurityComponentTest extends CakeTestCase { * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); + $request = new CakeRequest('posts/index', false); $request->addParams(array('controller' => 'posts', 'action' => 'index')); $this->Controller = new SecurityTestController($request); $this->Controller->Components->init($this->Controller); $this->Controller->Security = $this->Controller->TestSecurity; $this->Controller->Security->blackHoleCallback = 'fail'; - $this->oldSalt = Configure::read('Security.salt'); + Configure::write('Security.salt', 'foo!'); } /** * Tear-down method. Resets environment state. * - * @access public * @return void */ - function endTest() { - Configure::write('Security.salt', $this->oldSalt); + function tearDown() { + parent::tearDown(); $this->Controller->Session->delete('_Token'); unset($this->Controller->Security); unset($this->Controller->Component); diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 2551b9443..f2f384cf1 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -275,12 +275,13 @@ class ScaffoldViewTest extends CakeTestCase { public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag'); /** - * startTest method + * setUp method * * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $this->request = new CakeRequest(null, false); $this->Controller = new ScaffoldMockController($this->request); $this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader')); @@ -292,15 +293,13 @@ class ScaffoldViewTest extends CakeTestCase { } /** - * endTest method + * teardown method * - * @access public * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Controller); - - App::build(); } /** @@ -687,24 +686,24 @@ class ScaffoldTest extends CakeTestCase { */ public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag'); /** - * startTest method + * setUp method * - * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $request = new CakeRequest(null, false); $this->Controller = new ScaffoldMockController($request); $this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader')); } /** - * endTest method + * tearDown method * - * @access public * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Controller); } diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 67614bca0..19a7d47b3 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -519,23 +519,22 @@ class CakeSchemaTest extends CakeTestCase { /** * setUp method * - * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $this->Schema = new TestAppSchema(); } /** * tearDown method * - * @access public * @return void */ function tearDown() { + parent::tearDown(); @unlink(TMP . 'tests' . DS .'schema.php'); unset($this->Schema); - ClassRegistry::flush(); } /** diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 4ae3532b3..f96fa1cf6 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1283,12 +1283,13 @@ class DboSourceTest extends CakeTestCase { ); /** - * startTest method + * setUp method * * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $this->__config = $this->db->config; if (!class_exists('DboTest')) { @@ -1325,8 +1326,7 @@ class DboSourceTest extends CakeTestCase { $this->testDb->cacheSources = false; $this->testDb->startQuote = '`'; $this->testDb->endQuote = '`'; - Configure::write('debug', 1); - $this->debug = Configure::read('debug'); + $this->Model = new TestModel(); } @@ -1336,11 +1336,9 @@ class DboSourceTest extends CakeTestCase { * @access public * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Model); - Configure::write('debug', $this->debug); - ClassRegistry::flush(); - unset($this->debug); } /** diff --git a/cake/tests/cases/libs/route/cake_route.test.php b/cake/tests/cases/libs/route/cake_route.test.php index 47fdef0f9..21f02ec56 100644 --- a/cake/tests/cases/libs/route/cake_route.test.php +++ b/cake/tests/cases/libs/route/cake_route.test.php @@ -10,24 +10,14 @@ App::import('Core', 'Router'); **/ class CakeRouteTestCase extends CakeTestCase { /** - * startTest method + * setUp method * * @access public * @return void */ - function startTest() { - $this->_routing = Configure::read('Routing'); + function setUp() { + parent::setUp(); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); - Router::reload(); - } - -/** - * end the test and reset the environment - * - * @return void - **/ - function endTest() { - Configure::write('Routing', $this->_routing); } /** diff --git a/cake/tests/cases/libs/route/plugin_short_route.test.php b/cake/tests/cases/libs/route/plugin_short_route.test.php index d52061844..4edda72b1 100644 --- a/cake/tests/cases/libs/route/plugin_short_route.test.php +++ b/cake/tests/cases/libs/route/plugin_short_route.test.php @@ -7,26 +7,16 @@ App::import('Core', 'route/PluginShortRoute'); */ class PluginShortRouteTestCase extends CakeTestCase { /** - * startTest method + * setUp method * - * @access public * @return void */ - function startTest() { - $this->_routing = Configure::read('Routing'); + function setUp() { + parent::setUp(); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); Router::reload(); } -/** - * end the test and reset the environment - * - * @return void - **/ - function endTest() { - Configure::write('Routing', $this->_routing); - } - /** * test the parsing of routes. * diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 94a45780b..7b176a8d5 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -38,18 +38,8 @@ class RouterTest extends CakeTestCase { * @return void */ function setUp() { - $this->_routing = Configure::read('Routing'); + parent::setUp(); Configure::write('Routing', array('admin' => null, 'prefixes' => array())); - Router::reload(); - } - -/** - * end the test and reset the environment - * - * @return void - */ - function endTest() { - Configure::write('Routing', $this->_routing); } /** diff --git a/cake/tests/cases/libs/session/cache_session.test.php b/cake/tests/cases/libs/session/cache_session.test.php index 4b45eb7cc..eb3be0fc5 100644 --- a/cake/tests/cases/libs/session/cache_session.test.php +++ b/cake/tests/cases/libs/session/cache_session.test.php @@ -57,7 +57,8 @@ class CacheSessionTest extends CakeTestCase { * * @return void */ - function setup() { + function setUp() { + parent::setUp() $this->storage = new CacheSession(); } @@ -66,7 +67,8 @@ class CacheSessionTest extends CakeTestCase { * * @return void */ - function teardown() { + function tearDown() { + parent::tearDown(); unset($this->storage); } diff --git a/cake/tests/cases/libs/test_manager.test.php b/cake/tests/cases/libs/test_manager.test.php index 8c2499dc4..5e3f9c652 100644 --- a/cake/tests/cases/libs/test_manager.test.php +++ b/cake/tests/cases/libs/test_manager.test.php @@ -48,6 +48,7 @@ class TestManagerTest extends CakeTestCase { * @return void */ public function setUp() { + parent::setUp(); $this->_countFiles = 0; $this->TestManager = new TestTestManager(); $this->testSuiteStub = $this->getMock('CakeTestSuite'); diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index f2942cd0c..cf14ed441 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -63,12 +63,14 @@ class HtmlHelperTest extends CakeTestCase { * @var string */ public $cDataStart = 'preg:/^\/\/[\s\r\n]*/'; + /** * html property * @@ -77,57 +79,26 @@ class HtmlHelperTest extends CakeTestCase { */ public $Html = null; -/** - * Backup of app encoding configuration setting - * - * @var string - * @access protected - */ - protected $_appEncoding; - -/** - * Backup of asset configuration settings - * - * @var string - * @access protected - */ - protected $_asset; - -/** - * Backup of debug configuration setting - * - * @var integer - * @access protected - */ - protected $_debug; - /** * setUp method * - * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $this->View = $this->getMock('View', array('addScript'), array(new TheHtmlTestController())); $this->Html = new HtmlHelper($this->View); $this->Html->request = new CakeRequest(null, false); $this->Html->request->webroot = ''; - $this->_appEncoding = Configure::read('App.encoding'); - $this->_asset = Configure::read('Asset'); - $this->_debug = Configure::read('debug'); } /** - * endTest method + * tearDown method * - * @access public * @return void */ - function endTest() { - Configure::write('App.encoding', $this->_appEncoding); - Configure::write('Asset', $this->_asset); - Configure::write('debug', $this->_debug); - ClassRegistry::flush(); + function tearDown() { + parent::tearDown(); unset($this->Html, $this->View); } diff --git a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php index 643665545..12716099a 100644 --- a/cake/tests/cases/libs/view/helpers/jquery_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/jquery_engine.test.php @@ -22,22 +22,24 @@ App::import('Helper', array('Html', 'Js', 'JqueryEngine')); class JqueryEngineHelperTest extends CakeTestCase { /** - * startTest + * setUp * * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $controller = null; $View = new View($controller); $this->Jquery = new JqueryEngineHelper($View); } /** - * end test + * tearDown * * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Jquery); } diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index 317921490..039d6ef4a 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -685,24 +685,23 @@ class JsHelperTest extends CakeTestCase { */ class JsBaseEngineTest extends CakeTestCase { /** - * startTest method + * setUp method * - * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $controller = null; $this->View = new View($controller); $this->JsEngine = new OptionEngineHelper($this->View); } /** - * endTest method + * tearDown method * - * @access public * @return void */ - function endTest() { - ClassRegistry::removeObject('view'); + function tearDown() { + parent::tearDown(); unset($this->JsEngine); } diff --git a/cake/tests/cases/libs/view/helpers/mootools_engine.test.php b/cake/tests/cases/libs/view/helpers/mootools_engine.test.php index 8b3d682fa..01b1b643b 100644 --- a/cake/tests/cases/libs/view/helpers/mootools_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/mootools_engine.test.php @@ -24,21 +24,25 @@ App::import('Helper', array('Html', 'Js', 'MootoolsEngine')); class MooEngineHelperTest extends CakeTestCase { /** - * startTest + * setUp * * @return void */ - function startTest() { - $this->Moo =& new MootoolsEngineHelper(); + function setUp() { + parent::setUp(); + $this->Moo = new MootoolsEngineHelper(); } + /** - * end test + * tearDown * * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Moo); } + /** * test selector method * diff --git a/cake/tests/cases/libs/view/helpers/number.test.php b/cake/tests/cases/libs/view/helpers/number.test.php index af15d0086..6d66d5930 100644 --- a/cake/tests/cases/libs/view/helpers/number.test.php +++ b/cake/tests/cases/libs/view/helpers/number.test.php @@ -31,17 +31,16 @@ class NumberHelperTest extends CakeTestCase { * helper property * * @var mixed null - * @access public */ public $helper = null; /** * setUp method * - * @access public * @return void */ - function startTest() { + function setUp() { + parent::setUp(); $view = $this->getMock('View', array(), array(), '', false); $this->Number = new NumberHelper($view); } @@ -52,7 +51,8 @@ class NumberHelperTest extends CakeTestCase { * @access public * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Number); } diff --git a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php index 4485a28f0..610e8d23a 100644 --- a/cake/tests/cases/libs/view/helpers/prototype_engine.test.php +++ b/cake/tests/cases/libs/view/helpers/prototype_engine.test.php @@ -22,20 +22,22 @@ App::import('Helper', array('Html', 'Js', 'PrototypeEngine')); class PrototypeEngineHelperTest extends CakeTestCase { /** - * startTest + * setUp * * @return void */ - function startTest() { - $this->Proto =& new PrototypeEngineHelper(); + function setUp() { + parent::setUp(); + $this->Proto = new PrototypeEngineHelper(); } /** - * end test + * tearDown * * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->Proto); } diff --git a/cake/tests/cases/libs/view/media.test.php b/cake/tests/cases/libs/view/media.test.php index 1fee29c22..36dbf1e6f 100644 --- a/cake/tests/cases/libs/view/media.test.php +++ b/cake/tests/cases/libs/view/media.test.php @@ -124,13 +124,12 @@ class TestMediaView extends MediaView { class MediaViewTest extends CakeTestCase { /** - * startTest method + * setUp method * - * @access public * @return void */ - function startTest() { - Router::reload(); + function setUp() { + parent::setUp(); $this->Controller =& new Controller(); $this->MediaController =& new MediaController(); $this->MediaController->viewPath = 'posts'; @@ -144,11 +143,11 @@ class MediaViewTest extends CakeTestCase { * @access public * @return void */ - function endTest() { + function tearDown() { + parent::tearDown(); unset($this->MediaView); unset($this->MediaController); unset($this->Controller); - ClassRegistry::flush(); } /** diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 207cb7d60..b1b9531ab 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -224,7 +224,7 @@ class ViewTest extends CakeTestCase { * @return void */ function setUp() { - Router::reload(); + parent::setUp(); $request = $this->getMock('CakeRequest'); $this->Controller = new Controller($request); @@ -239,8 +239,7 @@ class ViewTest extends CakeTestCase { TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS ) ), true); - - $this->_debug = Configure::read('debug'); + Configure::write('debug', 2); } @@ -251,12 +250,10 @@ class ViewTest extends CakeTestCase { * @return void */ function tearDown() { + parent::tearDown(); unset($this->View); unset($this->PostsController); unset($this->Controller); - - App::build(); - Configure::write('debug', $this->_debug); } /** diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 5a9cb87ed..353243485 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -52,7 +52,8 @@ class XmlTest extends CakeTestCase { * @return void */ function setUp() { - $manager =& new XmlManager(); + parent::setUp(); + $manager = new XmlManager(); $manager->namespaces = array(); } diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index 993a5f796..6580eaec4 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -60,6 +60,13 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { */ private $fixtures = array(); +/** + * Configure values to restore at end of test. + * + * @var array + */ + protected $_configure = array(); + /** * Runs the test case and collects the results in a TestResult object. * If no TestResult object is passed a new one will be created. @@ -112,6 +119,33 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { return $shouldSkip; } +/** + * setup the test case, backup the static object values so they can be restored. + * + * @return void + */ + public function setUp() { + parent::setUp(); + $this->_configure = Configure::read(); + if (class_exists('Router', false)) { + Router::reload(); + } + } + +/** + * teardown any static object changes and restore them. + * + * @return void + */ + public function tearDown() { + parent::tearDown(); + App::build(); + if (class_exists('ClassRegistry', false)) { + ClassRegistry::flush(); + } + Configure::write($this->_configure); + } + /** * Announces the start of a test. *