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

Show more help text after generating a migration. #673

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
9 changes: 2 additions & 7 deletions lib/Doctrine/Migrations/MigrationDiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Provider\SchemaProviderInterface;
use RuntimeException;
use function preg_match;
Expand All @@ -17,9 +16,6 @@

class MigrationDiffGenerator
{
/** @var Configuration */
private $configuration;

/** @var DBALConfiguration */
private $dbalConfiguration;

Expand All @@ -39,15 +35,13 @@ class MigrationDiffGenerator
private $migrationSqlGenerator;

public function __construct(
Configuration $configuration,
DBALConfiguration $dbalConfiguration,
AbstractSchemaManager $schemaManager,
SchemaProviderInterface $schemaProvider,
AbstractPlatform $platform,
MigrationGenerator $migrationGenerator,
MigrationSqlGenerator $migrationSqlGenerator
) {
$this->configuration = $configuration;
$this->dbalConfiguration = $dbalConfiguration;
$this->schemaManager = $schemaManager;
$this->schemaProvider = $schemaProvider;
Expand All @@ -57,6 +51,7 @@ public function __construct(
}

public function generate(
string $versionNumber,
?string $filterExpression,
bool $formatted = false,
int $lineLength = 120
Expand Down Expand Up @@ -86,7 +81,7 @@ public function generate(
}

return $this->migrationGenerator->generateMigration(
$this->configuration->generateVersionNumber(),
$versionNumber,
$up,
$down
);
Expand Down
18 changes: 16 additions & 2 deletions lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public function execute(
}
}

$versionNumber = $this->configuration->generateVersionNumber();

$path = $this->createMigrationDiffGenerator()->generate(
$versionNumber,
$filterExpression,
$formatted,
$lineLength
Expand All @@ -101,13 +104,24 @@ public function execute(
$this->procOpen($editorCommand, $path);
}

$output->writeln(sprintf('Generated new migration class to "<info>%s</info>"', $path));
$output->writeln([
sprintf('Generated new migration class to "<info>%s</info>"', $path),
'',
sprintf(
'To run just this migration for testing purposes, you can use <info>migrations:execute --up %s</info>',
$versionNumber
),
'',
sprintf(
'To revert the migration you can use <info>migrations:execute --down %s</info>',
$versionNumber
),
]);
}

protected function createMigrationDiffGenerator() : MigrationDiffGenerator
{
return new MigrationDiffGenerator(
$this->configuration,
$this->connection->getConfiguration(),
$this->connection->getSchemaManager(),
$this->getSchemaProvider(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ public function execute(InputInterface $input, OutputInterface $output) : void
$this->procOpen($editorCommand, $path);
}

$output->writeln(sprintf('Generated new migration class to "<info>%s</info>"', $path));
$output->writeln([
sprintf('Generated new migration class to "<info>%s</info>"', $path),
'',
sprintf(
'To run just this migration for testing purposes, you can use <info>migrations:execute --up %s</info>',
$versionNumber
),
'',
sprintf(
'To revert the migration you can use <info>migrations:execute --down %s</info>',
$versionNumber
),
]);
}

protected function procOpen(string $editorCommand, string $path) : void
Expand Down
12 changes: 1 addition & 11 deletions tests/Doctrine/Migrations/Tests/MigrationDiffGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\MigrationDiffGenerator;
use Doctrine\Migrations\MigrationGenerator;
use Doctrine\Migrations\MigrationSqlGenerator;
Expand All @@ -18,9 +17,6 @@

class MigrationDiffGeneratorTest extends TestCase
{
/** @var Configuration */
private $configuration;

/** @var DBALConfiguration */
private $dbalConfiguration;

Expand Down Expand Up @@ -110,21 +106,16 @@ public function testGenerate() : void
->with(['UPDATE table SET value = 1'], true, 80)
->willReturn('test2');

$this->configuration->expects($this->once())
->method('generateVersionNumber')
->willReturn('1234');

$this->migrationGenerator->expects($this->once())
->method('generateMigration')
->with('1234', 'test1', 'test2')
->willReturn('path');

self::assertEquals('path', $this->migrationDiffGenerator->generate('/table_name1/', true, 80));
self::assertEquals('path', $this->migrationDiffGenerator->generate('1234', '/table_name1/', true, 80));
}

protected function setUp() : void
{
$this->configuration = $this->createMock(Configuration::class);
$this->dbalConfiguration = $this->createMock(DBALConfiguration::class);
$this->schemaManager = $this->createMock(AbstractSchemaManager::class);
$this->schemaProvider = $this->createMock(SchemaProviderInterface::class);
Expand All @@ -134,7 +125,6 @@ protected function setUp() : void
$this->migrationDiffGenerator = $this->createMock(MigrationDiffGenerator::class);

$this->migrationDiffGenerator = new MigrationDiffGenerator(
$this->configuration,
$this->dbalConfiguration,
$this->schemaManager,
$this->schemaProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\Migrations\Tests\Tools\Console\Command;

use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\MigrationDiffGenerator;
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
use PHPUnit\Framework\TestCase;
Expand All @@ -15,6 +16,9 @@ final class DiffCommandTest extends TestCase
/** @var MigrationDiffGenerator */
private $migrationDiffGenerator;

/** @var Configuration */
private $configuration;

/** @var DiffCommand */
private $diffCommand;

Expand All @@ -23,6 +27,10 @@ public function testExecute() : void
$input = $this->createMock(InputInterface::class);
$output = $this->createMock(OutputInterface::class);

$this->configuration->expects($this->once())
->method('generateVersionNumber')
->willReturn('1234');

$input->expects($this->at(0))
->method('getOption')
->with('filter-expression')
Expand All @@ -43,9 +51,13 @@ public function testExecute() : void
->with('editor-cmd')
->willReturn('mate');

$this->configuration->expects($this->once())
->method('generateVersionNumber')
->willReturn('1234');

$this->migrationDiffGenerator->expects($this->once())
->method('generate')
->with('filter expression', true, 80)
->with('1234', 'filter expression', true, 80)
->willReturn('/path/to/migration.php');

$this->diffCommand->expects($this->once())
Expand All @@ -54,19 +66,28 @@ public function testExecute() : void

$output->expects($this->once())
->method('writeln')
->with('Generated new migration class to "<info>/path/to/migration.php</info>"');
->with([
'Generated new migration class to "<info>/path/to/migration.php</info>"',
'',
'To run just this migration for testing purposes, you can use <info>migrations:execute --up 1234</info>',
'',
'To revert the migration you can use <info>migrations:execute --down 1234</info>',
]);

$this->diffCommand->execute($input, $output);
}

protected function setUp() : void
{
$this->migrationDiffGenerator = $this->createMock(MigrationDiffGenerator::class);
$this->configuration = $this->createMock(Configuration::class);

$this->diffCommand = $this->getMockBuilder(DiffCommand::class)
->setMethods(['createMigrationDiffGenerator', 'procOpen'])
->getMock();

$this->diffCommand->setMigrationConfiguration($this->configuration);

$this->diffCommand->expects($this->once())
->method('createMigrationDiffGenerator')
->willReturn($this->migrationDiffGenerator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ public function testExecute() : void

$output->expects($this->once())
->method('writeln')
->with('Generated new migration class to "<info>/path/to/migration.php</info>"');
->with([
'Generated new migration class to "<info>/path/to/migration.php</info>"',
'',
'To run just this migration for testing purposes, you can use <info>migrations:execute --up 1234</info>',
'',
'To revert the migration you can use <info>migrations:execute --down 1234</info>',
]);

$this->generateCommand->execute($input, $output);
}
Expand Down