/** * print differences on screen */ public function diffAction() { $module = $this->request->getParam('module'); if ($module) { $this->console->writeLine('Only for module "' . $module . '":'); } $whiteList = $this->request->getParam('whitelist'); $blackList = $this->request->getParam('blacklist'); try { $result = $this->manager->generateMigration($module, $blackList, $whiteList, true); if (!empty($result)) { $this->console->writeLine('Queries (' . sizeof($result['up']) . ') :' . PHP_EOL); if (sizeof($result['up']) > 0) { foreach ($result['up'] as $diff) { $this->console->writeLine(stripcslashes($diff) . PHP_EOL); } } } else { $this->console->writeLine('Your database has no changes from last revision!'); } } catch (ZFCToolException $e) { $this->console->writeLine($e->getMessage(), Color::RED); } catch (\Exception $e) { $this->console->writeLine($e->getMessage(), Color::RED); } }
/** * 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); }