Register a single migration version to be executed by a AbstractMigration
class.
public registerMigration ( string $version, string $class ) : |
||
$version | string | The version of the migration in the format YYYYMMDDHHMMSS. |
$class | string | The migration class to execute for the version. |
Результат |
/** * @see https://github.com/doctrine/migrations/issues/61 * @group regresion * @dataProvider provideTestMigrationNames */ public function testMigrateExecutesOlderVersionsThatHaveNetYetBeenMigrated(array $migrations) { foreach ($migrations as $key => $class) { $migration = new \Doctrine\DBAL\Migrations\Migration($this->config); $this->config->registerMigration($key, $class); $sql = $migration->migrate(); $this->assertCount(1, $sql, 'should have executed one migration'); } }
public function testMigrateToCurrentVersionReturnsEmpty() { $this->config->registerMigration(1, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrateAddSqlTest'); $this->config->registerMigration(2, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrationMigrateFurther'); $migration = new \Doctrine\DBAL\Migrations\Migration($this->config); $migration->migrate(); $sql = $migration->migrate(); $this->assertEquals(array(), $sql); }
public function testAddSql() { $this->config->registerMigration(1, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrateAddSqlTest'); $migration = new \Doctrine\DBAL\Migrations\Migration($this->config); $migration->migrate(1); $migrations = $this->config->getMigrations(); $this->assertTrue($migrations[1]->isMigrated()); $schema = $this->config->getConnection()->getSchemaManager()->createSchema(); $this->assertTrue($schema->hasTable('test_add_sql_table')); $check = $this->config->getConnection()->fetchAll('select * from test_add_sql_table'); $this->assertNotEmpty($check); $this->assertEquals('test', $check[0]['test']); $migration->migrate(0); $this->assertFalse($migrations[1]->isMigrated()); $schema = $this->config->getConnection()->getSchemaManager()->createSchema(); $this->assertFalse($schema->hasTable('test_add_sql_table')); }
/** * Test "--delete" option on not migrated version. * * @expectedException InvalidArgumentException * @expectedExceptionMessage The version "1233" does not exists in the version table. */ public function testDeleteOptionIfVersionNotMigrated() { $this->configuration->registerMigration(1233, 'Doctrine\\DBAL\\Migrations\\Tests\\Stub\\Version1Test'); $commandTester = new CommandTester($this->command); $commandTester->execute(array('--delete' => true, 'version' => 1233), array('interactive' => false)); }
/** * {@inheritdoc} */ public function registerMigration($version, $class) { $this->ensureMigrationClassExists($class); parent::registerMigration($version, $class); }