Skip to content
Permalink
Browse files

Making schema shell test more robust by deleting files it makes in te…

…ardown().
  • Loading branch information...
markstory committed Sep 21, 2010
1 parent 309d08d commit 0bb23095f33c5cd816feb1663ce3925a4eed0a56
Showing with 19 additions and 21 deletions.
  1. +19 −21 cake/tests/cases/console/libs/schema.test.php
@@ -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')
@@ -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();
}
/**
@@ -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);
@@ -236,8 +241,6 @@ public function testDumpWithFileWriting() {
$this->assertPattern('/locale/', $contents);
$this->assertPattern('/foreign_key/', $contents);
$this->assertPattern('/content/', $contents);
$sql->delete();
}
/**
@@ -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();
}
@@ -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'
@@ -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);
@@ -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();
}
/**
@@ -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();
}
/**
@@ -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.
You can’t perform that action at this time.