Skip to content

Commit

Permalink
Adding formatted option for migration command
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRenaux committed Aug 14, 2023
1 parent 79c710b commit 5f9232b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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')
;
}

$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')) {
$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()
->addRequiredPackageVersion('doctrine/doctrine-migrations-bundle', '>=3')
->run(function (MakerTestRunner $runner) {
$runner->runConsole('make:migration', [], '--formatted');

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

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

0 comments on commit 5f9232b

Please sign in to comment.