From 63f5e6d6c183f8756409987ef93dbcc6042e0b2c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 12 Dec 2022 17:50:09 +0100 Subject: [PATCH 1/2] Add link to new migration files --- src/Maker/MakeMigration.php | 23 ++++++++++++++--------- src/Resources/config/makers.xml | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Maker/MakeMigration.php b/src/Maker/MakeMigration.php index e04c5fa63..7635f0ee2 100644 --- a/src/Maker/MakeMigration.php +++ b/src/Maker/MakeMigration.php @@ -20,6 +20,7 @@ use Symfony\Bundle\MakerBundle\Generator; use Symfony\Bundle\MakerBundle\InputConfiguration; use Symfony\Bundle\MakerBundle\Util\CliOutputHelper; +use Symfony\Bundle\MakerBundle\Util\MakerFileLinkFormatter; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArgvInput; @@ -34,8 +35,10 @@ final class MakeMigration extends AbstractMaker implements ApplicationAwareMaker { private Application $application; - public function __construct(private string $projectDir) - { + public function __construct( + private string $projectDir, + private ?MakerFileLinkFormatter $makerFileLinkFormatter = null, + ) { } public static function getCommandName(): string @@ -116,13 +119,15 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen return; } - $this->writeSuccessMessage($io); + $absolutePath = $this->getGeneratedMigrationFilename($migrationOutput); + $relativePath = str_replace($this->projectDir.'/', '', $absolutePath); - $migrationName = $this->getGeneratedMigrationFilename($migrationOutput); + $io->comment('created: '.($this->makerFileLinkFormatter?->makeLinkedPath($absolutePath, $relativePath) ?? $relativePath)); + + $this->writeSuccessMessage($io); $io->text([ - sprintf('Next: Review the new migration %s', $migrationName), - sprintf('Then: Run the migration with %s doctrine:migrations:migrate', CliOutputHelper::getCommandPrefix()), + sprintf('Review the new migration then run it with %s doctrine:migrations:migrate', CliOutputHelper::getCommandPrefix()), 'See https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html', ]); } @@ -148,12 +153,12 @@ public function configureDependencies(DependencyBuilder $dependencies) private function getGeneratedMigrationFilename(string $migrationOutput): string { - preg_match('#"(.*?)"#', $migrationOutput, $matches); + preg_match('#"(.*?)"#', $migrationOutput, $matches); - if (!isset($matches[0])) { + if (!isset($matches[1])) { throw new \Exception('Your migration generated successfully, but an error occurred printing the summary of what occurred.'); } - return str_replace($this->projectDir.'/', '', $matches[0]); + return $matches[1]; } } diff --git a/src/Resources/config/makers.xml b/src/Resources/config/makers.xml index 93f321e9b..e3d785cb0 100644 --- a/src/Resources/config/makers.xml +++ b/src/Resources/config/makers.xml @@ -133,6 +133,7 @@ %kernel.project_dir% + From 0d109ba589708aba510b577996e58a2791172413 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Mon, 12 Dec 2022 13:17:27 -0500 Subject: [PATCH 2/2] fix msg output assertion --- tests/Maker/MakeMigrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Maker/MakeMigrationTest.php b/tests/Maker/MakeMigrationTest.php index 4af643222..cff1b3191 100644 --- a/tests/Maker/MakeMigrationTest.php +++ b/tests/Maker/MakeMigrationTest.php @@ -62,7 +62,7 @@ public function getTestDetails(): \Generator // see that the exact filename is in the output $iterator = $finder->getIterator(); $iterator->rewind(); - $this->assertStringContainsString(sprintf('"%s/%s"', $migrationsDirectoryPath, $iterator->current()->getFilename()), $output); + $this->assertStringContainsString(sprintf('%s/%s', $migrationsDirectoryPath, $iterator->current()->getFilename()), $output); }), ];