1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-migrations.git synced 2024-06-16 15:01:08 +03:00

Changing tests to auto-create and auto-teardown the testing table fixes #5

This commit is contained in:
Matt Button 2011-02-16 23:04:19 +00:00
parent 12670e28ef
commit 17b36782e1
2 changed files with 25 additions and 35 deletions

View file

@ -1,34 +0,0 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Create test_minion_migrations table
*/
class Migration_Minion_20110110093709 extends Minion_Migration_Base {
/**
* Run queries needed to apply this migration
*
* @param Kohana_Database Database connection
*/
public function up(Kohana_Database $db)
{
$db->query(NULL, 'CREATE TABLE `test_minion_migrations` (
`timestamp` varchar(14) NOT NULL,
`description` varchar(100) NOT NULL,
`location` varchar(100) NOT NULL,
`applied` tinyint(1) DEFAULT \'0\',
PRIMARY KEY (`timestamp`,`location`),
UNIQUE KEY `MIGRATION_ID` (`timestamp`,`description`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;');
}
/**
* Run queries needed to remove this migration
*
* @param Kohana_Database Database connection
*/
public function down(Kohana_Database $db)
{
$db->query(NULL, 'DROP TABLE `test_minion_migrations`');
}
}

View file

@ -4,9 +4,33 @@
* Test for the migration model
*
* @group minion
**/
* @group minion.tasks
* @group minion.tasks.migrations
*/
class Minion_Migration_ModelTest extends Kohana_Unittest_Database_TestCase
{
/**
* Runs before the test class as a whole is ran
* Creates the test table
*/
public static function setUpBeforeClass()
{
$sql = file_get_contents(Kohana::find_file('', 'minion_schema', 'sql'));
$sql = str_replace('`minion_migrations`', '`test_minion_migrations`', $sql);
Database::instance()->query(NULL, 'DROP TABLE IF EXISTS `test_minion_migrations`');
Database::instance()->query(NULL, $sql);
}
/**
* Removes the test tables after the tests have finished
*/
public static function tearDownAfterClass()
{
Database::instance()->query(NULL, 'DROP TABLE `test_minion_migrations`');
}
/**
* Gets the dataset that should be used to populate db
*