Skip to content

Commit 717e12d

Browse files
[make:migration] Add link to new migration files (#1253)
* Add link to new migration files * fix msg output assertion Co-authored-by: Jesse Rushlow <[email protected]>
1 parent 16f26e4 commit 717e12d

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/Maker/MakeMigration.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Bundle\MakerBundle\Generator;
2121
use Symfony\Bundle\MakerBundle\InputConfiguration;
2222
use Symfony\Bundle\MakerBundle\Util\CliOutputHelper;
23+
use Symfony\Bundle\MakerBundle\Util\MakerFileLinkFormatter;
2324
use Symfony\Component\Console\Application;
2425
use Symfony\Component\Console\Command\Command;
2526
use Symfony\Component\Console\Input\ArgvInput;
@@ -34,8 +35,10 @@ final class MakeMigration extends AbstractMaker implements ApplicationAwareMaker
3435
{
3536
private Application $application;
3637

37-
public function __construct(private string $projectDir)
38-
{
38+
public function __construct(
39+
private string $projectDir,
40+
private ?MakerFileLinkFormatter $makerFileLinkFormatter = null,
41+
) {
3942
}
4043

4144
public static function getCommandName(): string
@@ -116,13 +119,15 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
116119
return;
117120
}
118121

119-
$this->writeSuccessMessage($io);
122+
$absolutePath = $this->getGeneratedMigrationFilename($migrationOutput);
123+
$relativePath = str_replace($this->projectDir.'/', '', $absolutePath);
120124

121-
$migrationName = $this->getGeneratedMigrationFilename($migrationOutput);
125+
$io->comment('<fg=blue>created</>: '.($this->makerFileLinkFormatter?->makeLinkedPath($absolutePath, $relativePath) ?? $relativePath));
126+
127+
$this->writeSuccessMessage($io);
122128

123129
$io->text([
124-
sprintf('Next: Review the new migration <info>%s</info>', $migrationName),
125-
sprintf('Then: Run the migration with <info>%s doctrine:migrations:migrate</info>', CliOutputHelper::getCommandPrefix()),
130+
sprintf('Review the new migration then run it with <info>%s doctrine:migrations:migrate</info>', CliOutputHelper::getCommandPrefix()),
126131
'See <fg=yellow>https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html</>',
127132
]);
128133
}
@@ -148,12 +153,12 @@ public function configureDependencies(DependencyBuilder $dependencies)
148153

149154
private function getGeneratedMigrationFilename(string $migrationOutput): string
150155
{
151-
preg_match('#"(.*?)"#', $migrationOutput, $matches);
156+
preg_match('#"<info>(.*?)</info>"#', $migrationOutput, $matches);
152157

153-
if (!isset($matches[0])) {
158+
if (!isset($matches[1])) {
154159
throw new \Exception('Your migration generated successfully, but an error occurred printing the summary of what occurred.');
155160
}
156161

157-
return str_replace($this->projectDir.'/', '', $matches[0]);
162+
return $matches[1];
158163
}
159164
}

src/Resources/config/makers.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133

134134
<service id="maker.maker.make_migration" class="Symfony\Bundle\MakerBundle\Maker\MakeMigration">
135135
<argument>%kernel.project_dir%</argument>
136+
<argument type="service" id="maker.file_link_formatter" />
136137
<tag name="maker.command" />
137138
</service>
138139

tests/Maker/MakeMigrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getTestDetails(): \Generator
6262
// see that the exact filename is in the output
6363
$iterator = $finder->getIterator();
6464
$iterator->rewind();
65-
$this->assertStringContainsString(sprintf('"%s/%s"', $migrationsDirectoryPath, $iterator->current()->getFilename()), $output);
65+
$this->assertStringContainsString(sprintf('%s/%s', $migrationsDirectoryPath, $iterator->current()->getFilename()), $output);
6666
}),
6767
];
6868

0 commit comments

Comments
 (0)