-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Use SymfonyStyle for command output #6655
Conversation
fyi @javiereguiluz ;-) |
$output->writeln(' Use the incremental update to detect changes during development and use'); | ||
$output->writeln(' the SQL DDL provided to manually update your database in production.'); | ||
$output->writeln(''); | ||
$this->io->caution(<<<EOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you prefer it, most methods accept both strings and arrays of strings, so this code could be:
$this->io->caution([
'This operation should not be executed in a production environment!',
'',
'Use the incremental update to detect changes during development and use',
'the SQL DDL provided to manually update your database in production.',
]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this afterwards 👍
I can rework this if the guys like the PR and prefer the array syntax.
Thank you for your feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array syntax looks better in my opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OskarStark some small suggestions here, thanks for your contribution, the command's output is indeed looking better.
In terms of branching, this is correct 😉.
@@ -39,6 +40,11 @@ | |||
class UpdateCommand extends AbstractCommand | |||
{ | |||
/** | |||
* @var SymfonyStyle | |||
*/ | |||
protected $io; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe ui
or userInterface
is a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, wouldn't it be better to have this property in the AbstractCommand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change this ofc, but I use $io
everywhere and it was mentioned in the official blog post, too. $ui
is a bit missleading IMO
@javiereguiluz what do you think, how do you use it?
Official blog post: https://symfony.com/blog/new-in-symfony-2-8-console-style-guide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just suggested that because IMO we're actually interacting with the CLI user interface 😄
$output->writeln(' Use the incremental update to detect changes during development and use'); | ||
$output->writeln(' the SQL DDL provided to manually update your database in production.'); | ||
$output->writeln(''); | ||
$this->io->caution(<<<EOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array syntax looks better in my opinion
@@ -109,13 +115,15 @@ protected function configure() | |||
*/ | |||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) | |||
{ | |||
$this->io = new SymfonyStyle($input, $output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be part of the AbstractCommand#execute()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it
@OskarStark just a remark, please make sure you send test updates too. |
Ok, lets check the build 😄 |
@@ -36,21 +37,24 @@ | |||
class CollectionRegionCommand extends Command | |||
{ | |||
/** | |||
* @var SymfonyStyle | |||
*/ | |||
protected $ui; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I see, ui
is not needed to be retained in internals: please convert it to a local variable wherever possible. If multiple private
methods rely on it, please pass it around as a call parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
$em = $this->getHelper('em')->getEntityManager(); | ||
$ownerClass = $input->getArgument('owner-class'); | ||
$assoc = $input->getArgument('association'); | ||
$ownerId = $input->getArgument('owner-id'); | ||
$cache = $em->getCache(); | ||
|
||
if ( ! $cache instanceof Cache) { | ||
if (!$cache instanceof Cache) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert these spacing changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -36,21 +37,24 @@ | |||
class CollectionRegionCommand extends Command | |||
{ | |||
/** | |||
* @var SymfonyStyle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SymfonyStyle|null
@@ -36,20 +37,23 @@ | |||
class EntityRegionCommand extends Command | |||
{ | |||
/** | |||
* @var SymfonyStyle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SymfonyStyle|null
@@ -39,23 +40,27 @@ | |||
class MetadataCommand extends Command | |||
{ | |||
/** | |||
* @var SymfonyStyle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SymfonyStyle|null
Hmm, this is a bit strange.
The any idea @Ocramius @javiereguiluz ? |
I found this: https://stackoverflow.com/questions/39190610/how-to-test-console-command-output-when-terminal-widths-differ/40347595#40347595
WDYT? |
lets check if 142055c makes travis happy 🎉 |
Fails:
works:
|
Looks like 2 travis builds are still failing.... I don't know why. Scrutinizer tests pass, after setting the COLUMNS env in |
https://github.com/doctrine/doctrine2/pull/6655/files#diff-354f30a63fb0907d4ad57269548329e3R12 fixes most of the travis builds, but |
I rebased my branch, but don't know if travis is working now |
any news? |
Not a single comment/feedback since the end of august, that makes me sad.... 😞 If you don't like it I will close the PR, otherwise I need some help how to fix it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't get to do any proper OSS since August either, sorry.
From my end, the patch looks simple/solid
@OskarStark is not about liking it or not, it's simply a matter of time. All maintainers all quite busy with paid work and we're doing our best to at least release bug fixes. I know that it's not ideal but I hope you understand our situation... |
Other similarity between failing jobs: |
damn, nothing is working 👎 |
You could try to add |
updated |
Looks like it is! That's progress 👍 |
I will have a look
damn, i did before, but squashed all commits, thought this was already done 😞
ofc, I will check, do you have a tool for that like StyleCi or a PHP-CS-Fixer config?
done |
I think it's fine to have 2 commits one that formats the old code and one that introduces
Yes, we use |
don't worry, I will do it, but how to proceed with Scrutinizer? set
ok, i checked for the space before and after |
@OskarStark I've merged the scrutinizer config to not run the tests there, please rebase your branch to sync with
Don't change anything on scrutinizer config =) |
rebased and splitted my commits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OskarStark great job with the commit organisation (and thanks for fixing gramar mistakes as well)!
I got some final nitpickings. For things related coding standard stuff I've just merged #6844 in, so that might help you check for possible issues (along with the tool that @morozov created).
@@ -105,6 +100,12 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
$message = ($result) ? 'Successfully flushed cache entries.' : $message; | |||
} | |||
|
|||
$output->writeln($message); | |||
if (!$result) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to fix CS here
@@ -53,7 +53,10 @@ public function testClearAllRegion() | |||
], ['decorated' => false] | |||
); | |||
|
|||
$this->assertEquals('Clearing all second-level cache collection regions' . PHP_EOL, $tester->getDisplay()); | |||
$this->assertContains( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use self::assert*
instead
@@ -68,7 +71,10 @@ public function testClearByOwnerEntityClassName() | |||
], ['decorated' => false] | |||
); | |||
|
|||
$this->assertEquals('Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay()); | |||
$this->assertContains( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use self::assert*
instead
@@ -84,7 +90,14 @@ public function testClearCacheEntryName() | |||
], ['decorated' => false] | |||
); | |||
|
|||
$this->assertEquals('Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner entity identified by "1"' . PHP_EOL, $tester->getDisplay()); | |||
$this->assertContains( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use self::assert*
instead
' // Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner', | ||
$tester->getDisplay() | ||
); | ||
$this->assertContains( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use self::assert*
instead
@@ -95,6 +104,9 @@ public function testFlushRegionName() | |||
], ['decorated' => false] | |||
); | |||
|
|||
$this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay()); | |||
$this->assertContains( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use self::assert*
instead
@@ -91,6 +91,6 @@ public function testWillShowQuery() | |||
) | |||
); | |||
|
|||
$this->assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay()); | |||
$this->assertStringMatchesFormat('SELECT %a', trim($this->tester->getDisplay())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use self::assert*
instead
|
||
if (!$entityClassNames) { | ||
throw new \Exception( | ||
'You do not have any mapped Doctrine ORM entities according to the current configuration. '. | ||
$ui->caution([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no test covering this, could you please add one?
$output->writeln("<error>[FAIL]</error> ".$entityClassName); | ||
$output->writeln(sprintf("<comment>%s</comment>", $e->getMessage())); | ||
$output->writeln(''); | ||
$ui->text([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no test covering this, could you please add one?
} | ||
} else { | ||
$output->writeln('No Metadata Classes to process.'); | ||
$ui->success('No Metadata Classes to process.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no test covering this, could you please add one?
@OskarStark thanks a lot for not giving up on this and sorry about the huge delays. We'll probably get this 🚢 by the end of the day! |
sounds good 😄
In the meantime you could give me another review if you find some time. Cheers 🍾 |
self::assertContains(City::class, $this->tester->getDisplay()); | ||
} | ||
|
||
public function testEmptyEntityClassNames() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lcobucci I tried to overwrite the HelperSet
with my mocked $em
like this, but it doesn't work:
// overwrite HelperSet to mock getAllClassNames()
$this->application->setHelperSet(
new HelperSet(['em' => new EntityManagerHelper($em)])
);
because of this I need to redo the whole setUp
logic in my tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, let's give it a shot but if it gets too complicated it means that we have a design issue and wouldn't be really correct to fix it in this PR (trade-offs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am done with the test, but will force push once you finished your review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can push it, I didn't start the review yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I will keep the separate commits, let me know if I should squash some of them together! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found some small issues, which I've already fixed 😄 (just to keep track of why I've introduced new changes here)
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this changes the behaviour of the command, we shouldn't do it
|
||
$output->writeln(sprintf(' <info>%s --force</info> to execute the command', $this->getName())); | ||
$output->writeln(sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName())); | ||
$ui->text( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not variadic, we should encapsulate things in an array
In order to simplify and standardise the definition of the commands.
These constants are available since PHP 5.4 and since we're requiring PHP 7.1 there's no reason to require them. I've also simplified the `array_map()` call since it's useless to define a closure that simply calls a function.
To simplify and organise the code (also replacing `$this->assert*` with `self::assert*`).
@OskarStark 🚢! Thanks a lot for your contribution (and patience)!! |
Yeah, finally 😃 🎉 🍾 Thank you for your detailed feedback! |
It's a shame I never got a reaction for PR #5651, posted over two years ago. I saw this PR via Twitter only today. |
|
||
// Outputting information message | ||
$ui->newLine(); | ||
$ui->text(sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this one and the above are left out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get what you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean those <info>
tags, I thought whole point of this PR is to eliminate/replace them with SymfonyStyle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we keep them, because the dest path should be green, and the rest of the text white
I started to implement
SymfonyStyle
to the commands, I will follow up with the other commands if you like this.Here are some screenshots:
Is the branch the correct one or shall I switch?
Cheers, Oskar