/** * @depends testCreateDumpSuccess */ public function testImportDumpSuccess() { $dumpFullPath = self::$manager->getDumpsDirectoryPath() . DIRECTORY_SEPARATOR . self::DUMP_FILE_NAME; if (is_file($dumpFullPath)) { // dispatch url $this->dispatch('import dump ' . self::DUMP_FILE_NAME); $this->assertResponseStatusCode(0); $this->assertActionName('import'); $this->assertControllerName('ZFCTool\\Controller\\Dump'); $this->assertControllerClass('DumpController'); $this->assertMatchedRouteName('import-dump'); $result = self::$db->query("SHOW TABLES LIKE '" . self::TABLE_NAME . "';", Adapter::QUERY_MODE_EXECUTE); $this->assertEquals(1, $result->count()); $db = new Mysql(self::$db); $db->dropTable(self::TABLE_NAME); } else { $this->fail('Dump file not exist!'); } }
/** * @depends testCreateSuccess */ public function testImportSuccess() { $dumpFullPath = self::$manager->getDumpsDirectoryPath(self::FIXTURE_MODULE) . DIRECTORY_SEPARATOR . self::DUMP_FILE_NAME; if (is_file($dumpFullPath)) { self::$manager->import(self::DUMP_FILE_NAME, self::FIXTURE_MODULE); $result = self::$db->query("SHOW TABLES LIKE '" . self::TABLE_NAME . "';", Adapter::QUERY_MODE_EXECUTE); $this->assertEquals(1, $result->count()); unlink($dumpFullPath); $db = new Mysql(self::$db); $db->dropTable(self::TABLE_NAME); } else { $this->fail('Dump file not exist!'); } }
/** * Test for method `generate` */ public function testGenerateMigrationSuccess() { $tableName = 'test_table'; //Test empty diff $result = self::$manager->generateMigration(null, '', $tableName); $this->assertFalse($result); $db = new Mysql(self::$db); $db->createTable($tableName); $db->createColumn($tableName, 'col1', AbstractMigration::TYPE_INT); $db->createColumn($tableName, 'col2', AbstractMigration::TYPE_VARCHAR, 50); //Test diff $diff = self::$manager->generateMigration(null, '', $tableName, true); $compareTo = array('down' => array(Database::dropTable($tableName)), 'up' => array(Database::dropTable($tableName), Database::createTable($tableName))); $this->assertEquals($compareTo, $diff); //Test create $migrationPath = self::$manager->generateMigration(null, '', $tableName); $this->assertTrue(is_file($migrationPath)); $migrationFile = file_get_contents($migrationPath); $this->assertContains('CREATE TABLE `' . $tableName . '`', $migrationFile); $this->assertContains('$this->query("DROP TABLE IF EXISTS `' . $tableName . '`");', $migrationFile); unlink($migrationPath); $db->dropTable($tableName); }