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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/FileManager.php
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
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->hasOption('formatted') && null !== $input->getOption('formatted')) {
StevenRenaux marked this conversation as resolved.
Show resolved Hide resolved
$options[] = '--formatted';
}

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

Expand Down
11 changes: 11 additions & 0 deletions tests/Maker/MakeMigrationTest.php
Expand Up @@ -131,5 +131,16 @@ public function getTestDetails(): \Generator
$this->assertStringNotContainsString('Success', $output);
}),
];

yield 'it_generate_a_formatted_migration' => [$this->createMakeMigrationTest()
StevenRenaux marked this conversation as resolved.
Show resolved Hide resolved
->addRequiredPackageVersion('doctrine/doctrine-migrations-bundle', '>=3')
->run(function (MakerTestRunner $runner) {
$runner->runConsole('make:migration', [], '--formatted');

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

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