Skip to content

Commit

Permalink
Making schema shell test more robust by deleting files it makes in te…
Browse files Browse the repository at this point in the history
…ardown().
  • Loading branch information
markstory committed Sep 25, 2010
1 parent 309d08d commit 0bb2309
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions cake/tests/cases/console/libs/schema.test.php
Expand Up @@ -115,11 +115,11 @@ class SchemaShellTest extends CakeTestCase {
);

/**
* startTest method
* setup method
*
* @return void
*/
public function startTest() {
public function setup() {
$this->Dispatcher = $this->getMock(
'ShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
Expand All @@ -136,8 +136,13 @@ public function startTest() {
*
* @return void
*/
public function endTest() {
public function teardown() {
ClassRegistry::flush();
if (!empty($this->file) && $this->file instanceof File) {
$this->file->delete();
unset($this->file);
}
App::build();
}

/**
Expand Down Expand Up @@ -226,8 +231,8 @@ public function testDumpWithFileWriting() {
$this->Shell->startup();
$this->Shell->dump();

$sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
$contents = $sql->read();
$this->file =& new File(TMP . 'tests' . DS . 'i18n.sql');
$contents = $this->file->read();
$this->assertPattern('/DROP TABLE/', $contents);
$this->assertPattern('/CREATE TABLE `i18n`/', $contents);
$this->assertPattern('/id/', $contents);
Expand All @@ -236,8 +241,6 @@ public function testDumpWithFileWriting() {
$this->assertPattern('/locale/', $contents);
$this->assertPattern('/foreign_key/', $contents);
$this->assertPattern('/content/', $contents);

$sql->delete();
}

/**
Expand All @@ -258,14 +261,14 @@ public function testDumpFileWritingWithPlugins() {
$this->Shell->expects($this->once())->method('_stop');
$this->Shell->dump();

$file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
$contents = $file->read();
$this->file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
$contents = $this->file->read();

$this->assertPattern('/CREATE TABLE `acos`/', $contents);
$this->assertPattern('/id/', $contents);
$this->assertPattern('/model/', $contents);

$file->delete();
$this->file->delete();
App::build();
}

Expand Down Expand Up @@ -344,7 +347,9 @@ public function testGenerateOverwrite() {
public function testGenerateWithPlugins() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
), true);
App::objects('plugin', null, false);

$this->Shell->params = array(
'plugin' => 'TestPlugin',
'connection' => 'test'
Expand All @@ -353,8 +358,8 @@ public function testGenerateWithPlugins() {
$this->Shell->Schema->path = TMP . 'tests' . DS;

$this->Shell->generate();
$file = new File(TMP . 'tests' . DS . 'schema.php');
$contents = $file->read();
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
$contents = $this->file->read();

$this->assertPattern('/class TestPluginSchema/', $contents);
$this->assertPattern('/var \$posts/', $contents);
Expand All @@ -363,9 +368,6 @@ public function testGenerateWithPlugins() {
$this->assertPattern('/var \$test_plugin_comments/', $contents);
$this->assertNoPattern('/var \$users/', $contents);
$this->assertNoPattern('/var \$articles/', $contents);

$file->delete();
App::build();
}

/**
Expand Down Expand Up @@ -453,8 +455,6 @@ public function testPluginParam() {
$this->Shell->startup();
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema';
$this->assertEqual($this->Shell->Schema->path, $expected);

App::build();
}

/**
Expand All @@ -478,7 +478,5 @@ public function testPluginDotSyntaxWithCreate() {
$sources = $db->listSources();
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));

$db->execute('DROP TABLE ' . $db->config['prefix'] . 'acos');
App::build();
}
$db->execute('DROP TABLE ' . $db->config['prefix'] . 'acos'); }
}

0 comments on commit 0bb2309

Please sign in to comment.