Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Doctrine\Migrations\Migration to Doctrine\Migrations\Migrator #671

Merged
merged 1 commit into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ deprecated in the `1.7.1` release to prepare for the BC break.

The `Doctrine\DBAL\Migrations\MigrationsVersion` class is no longer available: please refrain from checking the Migrations version at runtime.

## BC Break: Moved `Doctrine\Migrations\Migration` to `Doctrine\Migrations\Migrator`

To make the name more clear and to differentiate from the `AbstractMigration` class, `Migration` was renamed to `Migrator`.

# Upgrade from 1.0-alpha1 to 1.0.0-alpha3

## AbstractMigration
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/Migrations/DependencyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ public function getMigrationStatusInfosHelper() : MigrationStatusInfosHelper
});
}

public function getMigration() : Migration
public function getMigrator() : Migrator
{
return $this->getDependency(Migration::class, function () {
return new Migration(
return $this->getDependency(Migrator::class, function () {
return new Migrator(
$this->configuration,
$this->getMigrationRepository(),
$this->getOutputWriter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function count;
use function sprintf;

class Migration
class Migrator
{
/** @var Configuration */
private $configuration;
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\Migrations\Tools\Console\Command;

use Doctrine\Migrations\Migration;
use Doctrine\Migrations\Migrator;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -95,7 +95,7 @@ protected function configure() : void

public function execute(InputInterface $input, OutputInterface $output) : int
{
$migration = $this->createMigration();
$migrator = $this->createMigrator();

$this->outputHeader($output);

Expand All @@ -122,16 +122,16 @@ public function execute(InputInterface $input, OutputInterface $output) : int

if ($path !== null) {
$path = $path === true ? getcwd() : $path;
$migration->writeSqlFile($path, $version);
$migrator->writeSqlFile($path, $version);

return 0;
}

$cancelled = false;

$migration->setNoMigrationException($allowNoMigration);
$migrator->setNoMigrationException($allowNoMigration);

$result = $migration->migrate(
$result = $migrator->migrate(
$version,
$dryRun,
$timeAllqueries,
Expand All @@ -154,9 +154,9 @@ function () use ($input, $output, &$cancelled) {
return 0;
}

protected function createMigration() : Migration
protected function createMigrator() : Migrator
{
return $this->dependencyFactory->getMigration();
return $this->dependencyFactory->getMigrator();
}

private function checkExecutedUnavailableMigrations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Exception\MigrationException;
use Doctrine\Migrations\Migration;
use Doctrine\Migrations\Migrator;
use Doctrine\Migrations\OutputWriter;
use Doctrine\Migrations\QueryWriter;
use Doctrine\Migrations\Tests\MigrationTestCase;
Expand Down Expand Up @@ -134,12 +134,12 @@ public function testVersionsTryToGetLoadedIfNotAlreadyLoadedWhenAccessingMethodT

$dependencyFactory = $configuration->getDependencyFactory();

$migration = new Migration(
$migrator = new Migrator(
$configuration,
$dependencyFactory->getMigrationRepository(),
$dependencyFactory->getOutputWriter()
);
$migration->migrate('3Test');
$migrator->migrate('3Test');

$result = call_user_func_array([$configuration, $method], $args);

Expand Down
69 changes: 35 additions & 34 deletions tests/Doctrine/Migrations/Tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public function testMigrateSeveralSteps() : void
self::assertInstanceOf(MigrationSkipMigration::class, $migrations['2']->getMigration());
self::assertInstanceOf(MigrationMigrateFurther::class, $migrations['3']->getMigration());

$migration = $this->createTestMigration($this->config);
$migration->migrate('3');
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate('3');

$schema = $this->config->getConnection()->getSchemaManager()->createSchema();
self::assertTrue($schema->hasTable('foo'));
Expand All @@ -145,8 +145,8 @@ public function testMigrateToLastVersion() : void
$this->config->registerMigration('2', MigrationSkipMigration::class);
$this->config->registerMigration('3', MigrationMigrateFurther::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate();
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate();

self::assertEquals(3, $this->config->getCurrentVersion());
$migrations = $this->config->getMigrations();
Expand All @@ -161,8 +161,8 @@ public function testDryRunMigration() : void
$this->config->registerMigration('2', MigrationSkipMigration::class);
$this->config->registerMigration('3', MigrationMigrateFurther::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate('3', true);
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate('3', true);

$schema = $this->config->getConnection()->getSchemaManager()->createSchema();
self::assertFalse($schema->hasTable('foo'));
Expand All @@ -181,10 +181,11 @@ public function testMigrateDownSeveralSteps() : void
$this->config->registerMigration('2', MigrationSkipMigration::class);
$this->config->registerMigration('3', MigrationMigrateFurther::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate('3');
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate('3');

self::assertEquals(3, $this->config->getCurrentVersion());
$migration->migrate('0');
$migrator->migrate('0');

$schema = $this->config->getConnection()->getSchemaManager()->createSchema();
self::assertFalse($schema->hasTable('foo'));
Expand All @@ -201,8 +202,8 @@ public function testAddSql() : void
{
$this->config->registerMigration('1', MigrateAddSqlTest::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate('1');
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate('1');

$migrations = $this->config->getMigrations();
self::assertTrue($migrations['1']->isMigrated());
Expand All @@ -213,7 +214,7 @@ public function testAddSql() : void
self::assertNotEmpty($check);
self::assertEquals('test', $check[0]['test']);

$migration->migrate('0');
$migrator->migrate('0');
self::assertFalse($migrations['1']->isMigrated());
$schema = $this->config->getConnection()->getSchemaManager()->createSchema();
self::assertFalse($schema->hasTable('test_add_sql_table'));
Expand All @@ -226,8 +227,8 @@ public function testAddSqlInPostUp() : void

$this->config->getConnection()->executeQuery(sprintf('CREATE TABLE IF NOT EXISTS %s (test INT)', $tableName));

$migration = $this->createTestMigration($this->config);
$migration->migrate('1');
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate('1');

$migrations = $this->config->getMigrations();
self::assertTrue($migrations['1']->isMigrated());
Expand All @@ -239,7 +240,7 @@ public function testAddSqlInPostUp() : void
self::assertNotEmpty($check);
self::assertEquals(3, $check);

$migration->migrate('0');
$migrator->migrate('0');
self::assertFalse($migrations['1']->isMigrated());

$check = $this->config->getConnection()->fetchColumn(
Expand All @@ -257,8 +258,8 @@ public function testVersionInDatabaseWithoutRegisteredMigrationStillMigrates() :
$this->config->registerMigration('1', MigrateAddSqlTest::class);
$this->config->registerMigration('10', MigrationMigrateFurther::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate();
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate();

$config = new Configuration($this->connection);
$config->setMigrationsNamespace('Doctrine\Migrations\Tests\Functional');
Expand All @@ -268,8 +269,8 @@ public function testVersionInDatabaseWithoutRegisteredMigrationStillMigrates() :
$config->setMigrationsTableName('test_migrations_table');
$config->setMigrationsColumnName('current_version');

$migration = $this->createTestMigration($config);
$migration->migrate();
$migrator = $this->createTestMigrator($config);
$migrator->migrate();

$migrations = $config->getMigrations();
self::assertTrue($migrations['1']->isMigrated());
Expand All @@ -283,8 +284,8 @@ public function testInterweavedMigrationsAreExecuted() : void
$this->config->registerMigration('1', MigrateAddSqlTest::class);
$this->config->registerMigration('3', MigrationMigrateFurther::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate();
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate();

$migrations = $this->config->getMigrations();
self::assertTrue($migrations['1']->isMigrated());
Expand All @@ -305,8 +306,8 @@ public function testInterweavedMigrationsAreExecuted() : void
self::assertArrayHasKey(2, $migrations);
self::assertEquals(2, $migrations['2']->getVersion());

$migration = $this->createTestMigration($config);
$migration->migrate();
$migrator = $this->createTestMigrator($config);
$migrator->migrate();

$migrations = $config->getMigrations();
self::assertTrue($migrations['1']->isMigrated());
Expand All @@ -321,10 +322,10 @@ public function testMigrateToCurrentVersionReturnsEmpty() : void
$this->config->registerMigration('1', MigrateAddSqlTest::class);
$this->config->registerMigration('2', MigrationMigrateFurther::class);

$migration = $this->createTestMigration($this->config);
$migration->migrate();
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate();

$sql = $migration->migrate();
$sql = $migrator->migrate();

self::assertEquals([], $sql);
}
Expand All @@ -339,9 +340,9 @@ public function testMigrateToCurrentVersionReturnsEmpty() : void
public function testMigrateExecutesOlderVersionsThatHaveNetYetBeenMigrated(array $migrations) : void
{
foreach ($migrations as $key => $class) {
$migration = $this->createTestMigration($this->config);
$migrator = $this->createTestMigrator($this->config);
$this->config->registerMigration((string) $key, $class);
$sql = $migration->migrate();
$sql = $migrator->migrate();
self::assertCount(1, $sql, 'should have executed one migration');
}
}
Expand Down Expand Up @@ -436,8 +437,8 @@ public function testSuccessfulMigrationDispatchesTheExpectedEvents() : void
$listener = new EventVerificationListener()
);

$migration = $this->createTestMigration($this->config);
$migration->migrate();
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate();

self::assertCount(4, $listener->events);

Expand All @@ -459,8 +460,8 @@ public function testSkippedMigrationsDispatchesTheExpectedEvents() : void
$listener = new EventVerificationListener()
);

$migration = $this->createTestMigration($this->config);
$migration->migrate();
$migrator = $this->createTestMigrator($this->config);
$migrator->migrate();

self::assertCount(4, $listener->events);

Expand All @@ -484,12 +485,12 @@ public function testMigrateWithConnectionWithAutoCommitOffStillPersistsChanges()
$listener = new AutoCommitListener();
list($conn, $config) = self::fileConnectionAndConfig();
$config->registerMigration('1', MigrateWithDataModification::class);
$migration = $this->createTestMigration($config);
$migrator = $this->createTestMigrator($config);
$conn->getEventManager()->addEventSubscriber($listener);
$conn->exec('CREATE TABLE test_data_migration (test INTEGER)');
$conn->commit();

$migration->migrate();
$migrator->migrate();

self::assertCount(3, $conn->fetchAll('SELECT * FROM test_data_migration'), 'migration did not execute');
$conn->close();
Expand Down
24 changes: 12 additions & 12 deletions tests/Doctrine/Migrations/Tests/MigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Exception\MigrationException;
use Doctrine\Migrations\Migration;
use Doctrine\Migrations\MigrationRepository;
use Doctrine\Migrations\Migrator;
use Doctrine\Migrations\OutputWriter;
use Doctrine\Migrations\QueryWriter;
use Doctrine\Migrations\Tests\Stub\Functional\MigrateNotTouchingTheSchema;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function testWriteSqlDown() : void

$sql = ['SELECT 1'];

$migration = $this->getMockBuilder(Migration::class)
$migration = $this->getMockBuilder(Migrator::class)
->setConstructorArgs([$configuration, $migrationRepository, $outputWriter])
->setMethods(['getSql'])
->getMock();
Expand Down Expand Up @@ -79,7 +79,7 @@ public function testWriteSqlDown() : void

public function testMigrateToUnknownVersionThrowsException() : void
{
$migration = $this->createTestMigration($this->config);
$migration = $this->createTestMigrator($this->config);

$this->expectException(MigrationException::class);
$this->expectExceptionMessage('Could not find migration version 1234');
Expand All @@ -89,7 +89,7 @@ public function testMigrateToUnknownVersionThrowsException() : void

public function testMigrateWithNoMigrationsThrowsException() : void
{
$migration = $this->createTestMigration($this->config);
$migration = $this->createTestMigrator($this->config);

$this->expectException(MigrationException::class);
$this->expectExceptionMessage('Could not find any migrations to execute.');
Expand All @@ -107,7 +107,7 @@ public function testMigrateWithNoMigrationsDontThrowsExceptionIfContiniousIntegr

$this->config->getOutputWriter()->setCallback($callback);

$migration = $this->createTestMigration($this->config);
$migration = $this->createTestMigrator($this->config);

$migration->setNoMigrationException(true);
$migration->migrate();
Expand All @@ -122,7 +122,7 @@ public function testMigrateWithNoMigrationsDontThrowsExceptionIfContiniousIntegr
public function testGetSql(?string $to) : void
{
/** @var Migration|\PHPUnit_Framework_MockObject_MockObject $migration */
$migration = $this->getMockBuilder(Migration::class)
$migration = $this->getMockBuilder(Migrator::class)
->disableOriginalConstructor()
->setMethods(['migrate'])
->getMock();
Expand Down Expand Up @@ -198,7 +198,7 @@ public function testWriteSqlFile(string $path, string $from, ?string $to, array
}

/** @var Migration|\PHPUnit_Framework_MockObject_MockObject $migration */
$migration = $this->getMockBuilder(Migration::class)
$migration = $this->getMockBuilder(Migrator::class)
->setConstructorArgs($this->getMigrationConstructorArgs($config))
->setMethods(['getSql'])
->getMock();
Expand Down Expand Up @@ -240,7 +240,7 @@ public function testMigrateWithMigrationsAndAddTheCurrentVersionOutputsANoMigrat
$this->config->createMigrationTable();
$this->conn->insert($this->config->getMigrationsTableName(), ['version' => '20160707000000']);

$migration = $this->createTestMigration($this->config);
$migration = $this->createTestMigrator($this->config);

$migration->migrate();

Expand All @@ -255,7 +255,7 @@ public function testMigrateReturnsFalseWhenTheConfirmationIsDeclined() : void
$this->config->registerMigration('20160707000000', MigrateNotTouchingTheSchema::class);
$this->config->createMigrationTable();
$called = false;
$migration = $this->createTestMigration($this->config);
$migration = $this->createTestMigrator($this->config);

$result = $migration->migrate(null, false, false, function () use (&$called) {
$called = true;
Expand All @@ -272,10 +272,10 @@ public function testMigrateWithDryRunDoesNotCallTheConfirmationCallback() : void
$this->config->setMigrationsNamespace('DoctrineMigrations\\');
$this->config->registerMigration('20160707000000', MigrateNotTouchingTheSchema::class);
$this->config->createMigrationTable();
$called = false;
$migration = $this->createTestMigration($this->config);
$called = false;
$migrator = $this->createTestMigrator($this->config);

$result = $migration->migrate(null, true, false, function () use (&$called) {
$result = $migrator->migrate(null, true, false, function () use (&$called) {
$called = true;
return false;
});
Expand Down
Loading