diff --git a/.gitignore b/.gitignore index 23b059a048..2254a57ad1 100644 --- a/.gitignore +++ b/.gitignore @@ -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. diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php index 10e3974a5e..2c6b002faf 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php @@ -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; @@ -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.' ); } @@ -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) { @@ -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'); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index e6a7cc6190..159a7575f3 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -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.' ) ->addOption( 'all-or-nothing', diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php index 5904b83b8a..82be37c97a 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php @@ -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');