From 717e12de64ac3557c53d485adf8f58b74f928762 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 12 Dec 2022 19:41:39 +0100 Subject: [PATCH] [make:migration] Add link to new migration files (#1253) * Add link to new migration files * fix msg output assertion Co-authored-by: Jesse Rushlow --- src/Maker/MakeMigration.php | 23 ++++++++++++++--------- src/Resources/config/makers.xml | 1 + tests/Maker/MakeMigrationTest.php | 2 +- 3 files changed, 16 insertions(+), 10 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% + 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); }), ];