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

Add option allow-empty-diff for diff command #840

Merged
merged 2 commits into from
Oct 8, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ phpunit.xml
/.phpcs-cache
/box.phar
/box.json

# Please don't add your IDE's files here, use global gitignore instead.
31 changes: 24 additions & 7 deletions lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Migrations\Tools\Console\Command;

use Doctrine\Migrations\Generator\DiffGenerator;
use Doctrine\Migrations\Generator\Exception\NoChangesDetected;
use Doctrine\Migrations\Provider\OrmSchemaProvider;
use Doctrine\Migrations\Provider\SchemaProviderInterface;
use Doctrine\Migrations\Tools\Console\Exception\InvalidOptionUsage;
Expand Down Expand Up @@ -83,6 +84,12 @@ protected function configure() : void
InputOption::VALUE_OPTIONAL,
'Check Database Platform to the generated code.',
true
)
->addOption(
'allow-empty-diff',
null,
InputOption::VALUE_NONE,
'Do not throw an exception when no changes are detected.'
alcaeus marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand All @@ -96,6 +103,7 @@ public function execute(
$filterExpression = $input->getOption('filter-expression') ?? null;
$formatted = (bool) $input->getOption('formatted');
$lineLength = (int) $input->getOption('line-length');
$allowEmptyDiff = (bool) $input->getOption('allow-empty-diff');
$checkDbPlatform = filter_var($input->getOption('check-database-platform'), FILTER_VALIDATE_BOOLEAN);

if ($formatted) {
Expand All @@ -108,13 +116,22 @@ public function execute(

$versionNumber = $this->configuration->generateVersionNumber();

$path = $this->createMigrationDiffGenerator()->generate(
$versionNumber,
$filterExpression,
$formatted,
$lineLength,
$checkDbPlatform
);
try {
$path = $this->createMigrationDiffGenerator()->generate(
$versionNumber,
$filterExpression,
$formatted,
$lineLength,
$checkDbPlatform
);
} catch (NoChangesDetected $exception) {
if ($allowEmptyDiff) {
$output->writeln($exception->getMessage());

return 0;
}
throw $exception;
}

$editorCommand = $input->getOption('editor-cmd');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function configure() : void
'allow-no-migration',
null,
InputOption::VALUE_NONE,
'Don\'t throw an exception if no migration is available (CI).'
'Do not throw an exception if no migration is available.'
jawira marked this conversation as resolved.
Show resolved Hide resolved
)
->addOption(
'all-or-nothing',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public function testExecute() : void

$input->expects(self::at(3))
->method('getOption')
->with('check-database-platform')
->with('allow-empty-diff')
->willReturn(true);

$input->expects(self::at(4))
->method('getOption')
->with('check-database-platform')
->willReturn(true);

$input->expects(self::at(5))
->method('getOption')
->with('editor-cmd')
->willReturn('mate');
Expand Down