Skip to content

Commit

Permalink
feature #1345 [make:migration] Format the generated migration sql by …
Browse files Browse the repository at this point in the history
…passing `--formatted` to the command

Co-authored-by: Maxime Pinot <contact@maximepinot.com>
  • Loading branch information
StevenRenaux and MaximePinot authored Mar 1, 2024
1 parent 8182644 commit 744ad00
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Maker/MakeMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection name')
;
}

$command
->addOption('formatted', null, InputOption::VALUE_NONE, 'Format the generated SQL');
}

public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
Expand All @@ -88,6 +91,10 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
}
// end 2.x support

if ($input->getOption('formatted')) {
$options[] = '--formatted';
}

$generateMigrationCommand = $this->application->find('doctrine:migrations:diff');
$generateMigrationCommandInput = new ArgvInput($options);

Expand Down
4 changes: 4 additions & 0 deletions src/Resources/help/MakeMigration.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
The <info>%command.name%</info> command generates a new migration:

<info>php %command.full_name%</info>

You can also generate a formatted migration with this option:

<info>php %command.full_name% --formatted</info>
11 changes: 11 additions & 0 deletions tests/Maker/MakeMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,16 @@ public function getTestDetails(): \Generator
$this->assertStringNotContainsString('Success', $output);
}),
];

yield 'it_generates_a_formatted_migration' => [$this->createMakeMigrationTest()
->addRequiredPackageVersion('doctrine/doctrine-migrations-bundle', '>=3')
->run(function (MakerTestRunner $runner) {
$runner->runConsole('make:migration', [], '--formatted');

$output = $runner->runMaker([/* no input */]);

$this->assertStringContainsString('Success', $output);
}),
];
}
}

0 comments on commit 744ad00

Please sign in to comment.