public function testGenerateAndCommitMigration()
 {
     $db = new Mysql(self::$db);
     $db->query(Database::dropTable(self::TABLE_NAME));
     $db->createTable(self::TABLE_NAME);
     $db->createColumn(self::TABLE_NAME, 'col1', AbstractMigration::TYPE_INT);
     $db->createColumn(self::TABLE_NAME, 'col2', AbstractMigration::TYPE_TEXT);
     // dispatch url
     $this->dispatch('gen migration -c --whitelist=' . self::TABLE_NAME);
     $this->assertResponseStatusCode(0);
     $this->assertActionName('generate');
     $this->assertControllerName('ZFCTool\\Controller\\Migration');
     $this->assertControllerClass('MigrationController');
     $this->assertMatchedRouteName('generate-migration');
     $response = ob_get_contents();
     preg_match("/[\\S]*\\.php/i", $response, $matches);
     $this->assertTrue(isset($matches[0]));
     $migrationPath = $matches[0];
     $this->assertTrue(is_file($migrationPath));
     preg_match("/\\d\\d\\d\\d\\d\\d\\d\\d_\\d\\d\\d\\d\\d\\d_\\d\\d/i", $migrationPath, $matches);
     $this->assertNotEmpty($matches);
     $migration = $matches[0];
     $lastMigration = self::$manager->getLastMigration();
     $this->assertArrayHasKey('migration', $lastMigration);
     $this->assertNotEquals(0, $lastMigration['migration']);
     $this->assertEquals($lastMigration['migration'], $migration);
     self::$manager->down(null);
     unlink($migrationPath);
 }
Beispiel #2
0
 /**
  * @dataProvider providerDownSuccess
  * @param $module
  * @param $migration
  * @param $tableFilter
  * @param $expected
  */
 public function testDownSuccess($module, $migration, $tableFilter, $expected)
 {
     self::$manager->up($module);
     $result = self::$db->query("SHOW TABLES LIKE '" . $tableFilter . "';", Adapter::QUERY_MODE_EXECUTE);
     $this->assertEquals(5, $result->count());
     self::$manager->down($module, $migration);
     $result = self::$db->query("SHOW TABLES LIKE '" . $tableFilter . "';", Adapter::QUERY_MODE_EXECUTE);
     $this->assertEquals($expected, $result->count());
     foreach ($result->toArray() as $data) {
         foreach ($data as $tableName) {
             self::$db->query("DROP TABLE `" . $tableName . "`", Adapter::QUERY_MODE_EXECUTE);
         }
     }
 }
Beispiel #3
0
 /**
  * down
  *
  */
 public function downAction()
 {
     $module = $this->request->getParam('module');
     if ($module) {
         $this->console->writeLine('Only for module "' . $module . '":');
     }
     $to = $this->request->getParam('to');
     $includeModules = $this->request->getParam('includemodules');
     try {
         $this->manager->down($module, $to, $includeModules);
         foreach ($this->manager->getMessages() as $message) {
             $this->console->writeLine($message, Color::GREEN);
         }
     } catch (ZFCToolException $e) {
         $this->console->writeLine($e->getMessage(), Color::RED);
     } catch (\Exception $e) {
         $this->console->writeLine($e->getMessage(), Color::RED);
     }
 }