/tests/MigrationManagerHelperTest.php
https://github.com/eugenix/dbmigrator · PHP · 188 lines · 133 code · 25 blank · 30 comment · 2 complexity · 799557c75e3006e508a2826dac72470b MD5 · raw file
- <?php
- require_once '../Helpers/MigrationManagerHelper.php';
- /**
- * Test class for MigrationManagerHelper.
- * Generated by PHPUnit on 2011-05-24 at 17:08:26.
- */
- class MigrationManagerHelperTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var MigrationManagerHelper
- */
- protected $object;
- protected $dbName = "testmigration";
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- $this->object = new MigrationManagerHelper('localhost', 'root', 'toor', $this->dbName);
- }
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- if ($this->object != null)
- $this->object->__destruct();
- }
- /**
- * @todo Implement testCreateTable().
- */
- public function testCreateTable()
- {
- $this->object->createTable();
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS count
- FROM information_schema.tables
- WHERE table_schema = '{$this->dbName}'
- AND table_name = '__migration'
- ");
- $this->assertEquals(1, mysql_result($res, 0), "Table migration must be exist");
- }
- /**
- * @todo Implement testMakeDBEmpty().
- */
- public function testMakeDBEmpty()
- {
- $this->object->makeDBEmpty();
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS count
- FROM information_schema.tables
- WHERE table_schema = '{$this->dbName}'
- ");
- $this->assertEquals(0, mysql_result($res, 0), "No tables");
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS COUNT
- FROM information_schema.triggers
- WHERE trigger_schema = '{$this->dbName}'
- ");
- $this->assertEquals(0, mysql_result($res, 0), "No triggers");
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS COUNT
- FROM information_schema.routines
- WHERE routine_schema = '{$this->dbName}'
- ");
- $this->assertEquals(0, mysql_result($res, 0), "No procedures and functions");
- }
- /**
- * @todo Implement testCheckDBError().
- */
- public function testCheckDBError()
- {
- try
- {
- $this->object->executeQuery("INVALID SQL");
- $this->fail("Must be exception");
- }
- catch (Exception $e)
- {
- $this->assertTrue(true, "Mysql exeptions");
- }
- }
- public function testCreateDump()
- {
- MigrationManagerHelper::cleanMigrDir('data/storage/0');
- $this->object->createDump('data/storage/0');
- $this->assertTrue(is_writable('data/storage/0/data.sql'));
- $this->assertTrue(is_writable('data/storage/0/procedures.sql'));
- $this->assertTrue(is_writable('data/storage/0/scheme.sql'));
- $this->assertTrue(is_writable('data/storage/0/triggers.sql'));
- }
- /**
- * @todo Implement testImportFiles().
- */
- public function testImportFiles()
- {
- $this->object->makeDBEmpty();
- $this->object->createTable();
- $this->object->importFiles('data/deltas/0',
- array('scheme.sql', 'data.sql', 'procedures.sql', 'triggers.sql'));
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS count
- FROM information_schema.tables
- WHERE table_schema = '{$this->dbName}'
- ");
- $this->assertEquals(24, mysql_result($res, 0), "24 tables");
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS COUNT
- FROM information_schema.triggers
- WHERE trigger_schema = '{$this->dbName}'
- ");
- $this->assertEquals(6, mysql_result($res, 0), "6 triggers");
- $res = $this->object->executeQuery("
- SELECT COUNT(*) AS COUNT
- FROM information_schema.routines
- WHERE routine_schema = '{$this->dbName}'
- ");
- $this->assertEquals(6, mysql_result($res, 0), "6 procedures");
- $this->object->makeDBEmpty();
- }
- /**
- * @todo Implement testCheckDir().
- */
- public function testCheckDir()
- {
- try
- {
- $this->object->checkDir('data/storage', 'test_migration');
- $this->assertTrue(true);
- }
- catch (Exception $e)
- {
- $this->fail('Thats ok');
- }
- }
- public function testCreateDeltaByBinaryLog()
- {
- $this->markTestSkipped();
- }
- public function testFilterQueries()
- {
- $queries = array(
- "/*!40019 SET @@session.max_insert_delayed_threads=0*/;",
- "use testmigration",
- "SET TIMESTAMP=1307451576",
- "SET @@session.pseudo_thread_id=999999999",
- "SET @@session.sql_mode=0",
- "/*!\C utf8 */",
- "BEGIN",
- "INSERT INTO migration (number, createTime, comment)
- VALUES (0, unix_timestamp(NOW()), 'Init migration')",
- "COMMIT",
- "DELIMITER ;",
- "ALTER TABLE `testmigration`.`actor` CHANGE `first_name` `first_name` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL",
- "ROLLBACK /* added by mysqlbinlog */;"
- );
- $queries = $this->object->filterQueries($queries);
- $this->assertEquals(6, count($queries));
- }
- }
- ?>