Skip to content

Commit

Permalink
Use stderr for messages directed at humans
Browse files Browse the repository at this point in the history
The name stderr is confusing, it should have been named stdnotify,
because it is meant for messages directed at humans, as opposed to
things that could be piped into another command.
We might have users that would want to pipe the output of --dump-sql
into an SQL client, and we ourselves need that feature for our tests to
continue working regardless of what extra warnings we may want to add.
See https://en.wikipedia.org/wiki/Filter_(software)#Unix
  • Loading branch information
greg0ire committed Oct 19, 2022
1 parent b05227e commit 78185f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"doctrine/lexer": "^1.2.3",
"doctrine/persistence": "^2.4 || ^3",
"psr/cache": "^1 || ^2 || ^3",
"symfony/console": "^3.0 || ^4.0 || ^5.0 || ^6.0",
"symfony/console": "^4.2 || ^5.0 || ^6.0",
"symfony/polyfill-php72": "^1.23",
"symfony/polyfill-php80": "^1.16"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ protected function configure()
*/
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
{
$errorStyle = $ui->getErrorStyle();
// Defining if update is complete or not (--complete not defined means $saveMode = true)
$saveMode = ! $input->getOption('complete');

if ($saveMode) {
$ui->warning('Not passing the "--complete" option to "orm:schema-tool:update" is deprecated and will not be supported when using doctrine/dbal 4');
$errorStyle->warning('Not passing the "--complete" option to "orm:schema-tool:update" is deprecated and will not be supported when using doctrine/dbal 4');
}

$sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);

if (empty($sqls)) {
$ui->success('Nothing to update - your database is already in sync with the current entity metadata.');
$errorStyle->success('Nothing to update - your database is already in sync with the current entity metadata.');

return 0;
}
Expand All @@ -102,22 +103,22 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
$ui->newLine();
}

$ui->text('Updating database schema...');
$ui->newLine();
$errorStyle->text('Updating database schema...');
$errorStyle->newLine();

$schemaTool->updateSchema($metadatas, $saveMode);

$pluralization = count($sqls) === 1 ? 'query was' : 'queries were';

$ui->text(sprintf(' <info>%s</info> %s executed', count($sqls), $pluralization));
$ui->success('Database schema updated successfully!');
$errorStyle->text(sprintf(' <info>%s</info> %s executed', count($sqls), $pluralization));
$errorStyle->success('Database schema updated successfully!');
}

if ($dumpSql || $force) {
return 0;
}

$ui->caution(
$errorStyle->caution(
[
'This operation should not be executed in a production environment!',
'',
Expand All @@ -126,7 +127,7 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $
]
);

$ui->text(
$errorStyle->text(
[
sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)),
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class UpdateCommandTest extends AbstractCommandTest
public function testItPrintsTheSql(): void
{
$tester = $this->getCommandTester(UpdateCommand::class);
$tester->execute(['--dump-sql' => true, '--complete' => true]);
$tester->execute(
['--dump-sql' => true],
['capture_stderr_separately' => true]
);

self::$sharedConn->executeStatement($tester->getDisplay());
}
Expand Down

0 comments on commit 78185f2

Please sign in to comment.