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

[make:migration] Format the generated migration sql by passing --formatted to the command #1345

Merged
merged 4 commits into from
Mar 1, 2024
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
1 change: 1 addition & 0 deletions src/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ private function realPath(string $absolutePath): string
}

$finalPath = implode('/', $finalParts);

// Normalize: // => /
// Normalize: /./ => /
return str_replace(['//', '/./'], '/', $finalPath);
Expand Down
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')
;
}

StevenRenaux marked this conversation as resolved.
Show resolved Hide resolved
$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);
}),
];
}
}
Loading