public function generate_new_migration_file($name, $actions_template = NULL) { $actions = new Migration_Actions($this->driver); if ($actions_template) { $actions->template(getcwd() . DIRECTORY_SEPARATOR . $actions_template); } else { $actions->parse($name); } $template = file_get_contents(Kohana::find_file('templates', 'migration', 'tpl')); $class_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))); $filename = sprintf("%d_{$name}.php", time()); file_put_contents($this->config['path'] . DIRECTORY_SEPARATOR . $filename, strtr($template, array('{up}' => join("\n", array_map('Migrations::indent', $actions->up)), '{down}' => join("\n", array_map('Migrations::indent', $actions->down)), '{class_name}' => $class_name))); return $filename; }
/** * @dataProvider data_parse_name */ public function test_parse_name($name, $method_name, $up, $down) { $driver = new Migration_Driver_Mysql(Kohana::TESTING); $actions = $this->getMock('Migration_Actions', array($method_name), array($driver)); $method = $actions->expects($this->once())->method($method_name); $actions->parse($name); $actions = new Migration_Actions($driver); $actions->parse($name); foreach ($up as $i => $up_action) { $this->assertArrayHasKey($i, $actions->up); $this->assertContains($up_action, $actions->up[$i]); } foreach ($down as $i => $down_action) { $this->assertArrayHasKey($i, $actions->down); $this->assertContains($down_action, $actions->down[$i]); } }