Skip to content

Commit

Permalink
Moving common setup and teardown functionality in to CakeTestCase.
Browse files Browse the repository at this point in the history
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 92b57d8
Show file tree
Hide file tree
Showing 34 changed files with 198 additions and 269 deletions.
10 changes: 1 addition & 9 deletions cake/tests/cases/console/cake.test.php
Expand Up @@ -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
Expand All @@ -176,15 +177,6 @@ public function setUp() {
), true);
}

/**
* tearDown method
*
* @return void
*/
public function tearDown() {
App::build();
}

/**
* testParseParams method
*
Expand Down
18 changes: 3 additions & 15 deletions cake/tests/cases/console/libs/acl.test.php
Expand Up @@ -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');
Expand All @@ -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
*
Expand Down
14 changes: 3 additions & 11 deletions cake/tests/cases/console/libs/api.test.php
Expand Up @@ -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')
Expand All @@ -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.
*
Expand Down
10 changes: 6 additions & 4 deletions cake/tests/cases/console/libs/bake.test.php
Expand Up @@ -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')
Expand All @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions cake/tests/cases/console/libs/tasks/db_config.test.php
Expand Up @@ -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'
));
Expand All @@ -87,9 +88,9 @@ public function startTest() {
*
* @return void
*/
public function endTest() {
public function tearDown() {
parent::tearDown();
unset($this->Task, $this->Dispatcher);
ClassRegistry::flush();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -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'
));
Expand All @@ -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();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -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'
));
Expand Down Expand Up @@ -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();
}

/**
Expand Down
45 changes: 14 additions & 31 deletions cake/tests/cases/console/libs/tasks/plugin.test.php
Expand Up @@ -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'
));
Expand All @@ -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));
}

/**
Expand All @@ -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';
Expand Down Expand Up @@ -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'));

Expand Down Expand Up @@ -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');
Expand Down
11 changes: 6 additions & 5 deletions cake/tests/cases/console/libs/tasks/project.test.php
Expand Up @@ -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'
));
Expand All @@ -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();
Expand Down
15 changes: 7 additions & 8 deletions cake/tests/cases/console/libs/tasks/view.test.php
Expand Up @@ -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'
));
Expand All @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion cake/tests/cases/libs/cake_log.test.php
Expand Up @@ -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);
Expand Down

0 comments on commit 92b57d8

Please sign in to comment.