mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making schema shell test more robust by deleting files it makes in teardown().
This commit is contained in:
parent
309d08d4ef
commit
0bb23095f3
1 changed files with 19 additions and 21 deletions
|
@ -115,11 +115,11 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* startTest method
|
* setup method
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function setup() {
|
||||||
$this->Dispatcher = $this->getMock(
|
$this->Dispatcher = $this->getMock(
|
||||||
'ShellDispatcher',
|
'ShellDispatcher',
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment', 'clear')
|
||||||
|
@ -136,8 +136,13 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function endTest() {
|
public function teardown() {
|
||||||
ClassRegistry::flush();
|
ClassRegistry::flush();
|
||||||
|
if (!empty($this->file) && $this->file instanceof File) {
|
||||||
|
$this->file->delete();
|
||||||
|
unset($this->file);
|
||||||
|
}
|
||||||
|
App::build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,8 +231,8 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$this->Shell->dump();
|
$this->Shell->dump();
|
||||||
|
|
||||||
$sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
|
$this->file =& new File(TMP . 'tests' . DS . 'i18n.sql');
|
||||||
$contents = $sql->read();
|
$contents = $this->file->read();
|
||||||
$this->assertPattern('/DROP TABLE/', $contents);
|
$this->assertPattern('/DROP TABLE/', $contents);
|
||||||
$this->assertPattern('/CREATE TABLE `i18n`/', $contents);
|
$this->assertPattern('/CREATE TABLE `i18n`/', $contents);
|
||||||
$this->assertPattern('/id/', $contents);
|
$this->assertPattern('/id/', $contents);
|
||||||
|
@ -236,8 +241,6 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->assertPattern('/locale/', $contents);
|
$this->assertPattern('/locale/', $contents);
|
||||||
$this->assertPattern('/foreign_key/', $contents);
|
$this->assertPattern('/foreign_key/', $contents);
|
||||||
$this->assertPattern('/content/', $contents);
|
$this->assertPattern('/content/', $contents);
|
||||||
|
|
||||||
$sql->delete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,14 +261,14 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->expects($this->once())->method('_stop');
|
$this->Shell->expects($this->once())->method('_stop');
|
||||||
$this->Shell->dump();
|
$this->Shell->dump();
|
||||||
|
|
||||||
$file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
|
$this->file =& new File(TMP . 'tests' . DS . 'dump_test.sql');
|
||||||
$contents = $file->read();
|
$contents = $this->file->read();
|
||||||
|
|
||||||
$this->assertPattern('/CREATE TABLE `acos`/', $contents);
|
$this->assertPattern('/CREATE TABLE `acos`/', $contents);
|
||||||
$this->assertPattern('/id/', $contents);
|
$this->assertPattern('/id/', $contents);
|
||||||
$this->assertPattern('/model/', $contents);
|
$this->assertPattern('/model/', $contents);
|
||||||
|
|
||||||
$file->delete();
|
$this->file->delete();
|
||||||
App::build();
|
App::build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +347,9 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
public function testGenerateWithPlugins() {
|
public function testGenerateWithPlugins() {
|
||||||
App::build(array(
|
App::build(array(
|
||||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||||
));
|
), true);
|
||||||
|
App::objects('plugin', null, false);
|
||||||
|
|
||||||
$this->Shell->params = array(
|
$this->Shell->params = array(
|
||||||
'plugin' => 'TestPlugin',
|
'plugin' => 'TestPlugin',
|
||||||
'connection' => 'test'
|
'connection' => 'test'
|
||||||
|
@ -353,8 +358,8 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
$this->Shell->Schema->path = TMP . 'tests' . DS;
|
||||||
|
|
||||||
$this->Shell->generate();
|
$this->Shell->generate();
|
||||||
$file = new File(TMP . 'tests' . DS . 'schema.php');
|
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
|
||||||
$contents = $file->read();
|
$contents = $this->file->read();
|
||||||
|
|
||||||
$this->assertPattern('/class TestPluginSchema/', $contents);
|
$this->assertPattern('/class TestPluginSchema/', $contents);
|
||||||
$this->assertPattern('/var \$posts/', $contents);
|
$this->assertPattern('/var \$posts/', $contents);
|
||||||
|
@ -363,9 +368,6 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->assertPattern('/var \$test_plugin_comments/', $contents);
|
$this->assertPattern('/var \$test_plugin_comments/', $contents);
|
||||||
$this->assertNoPattern('/var \$users/', $contents);
|
$this->assertNoPattern('/var \$users/', $contents);
|
||||||
$this->assertNoPattern('/var \$articles/', $contents);
|
$this->assertNoPattern('/var \$articles/', $contents);
|
||||||
|
|
||||||
$file->delete();
|
|
||||||
App::build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -453,8 +455,6 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$this->Shell->startup();
|
$this->Shell->startup();
|
||||||
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema';
|
$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);
|
$this->assertEqual($this->Shell->Schema->path, $expected);
|
||||||
|
|
||||||
App::build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -478,7 +478,5 @@ class SchemaShellTest extends CakeTestCase {
|
||||||
$sources = $db->listSources();
|
$sources = $db->listSources();
|
||||||
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));
|
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));
|
||||||
|
|
||||||
$db->execute('DROP TABLE ' . $db->config['prefix'] . 'acos');
|
$db->execute('DROP TABLE ' . $db->config['prefix'] . 'acos'); }
|
||||||
App::build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue