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

Use SymfonyStyle for command output #6655

Merged
merged 4 commits into from
Nov 24, 2017
Merged

Use SymfonyStyle for command output #6655

merged 4 commits into from
Nov 24, 2017

Conversation

OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Aug 29, 2017

I started to implement SymfonyStyle to the commands, I will follow up with the other commands if you like this.

Here are some screenshots:
screenshot 2017-08-29 15 18 23
screenshot 2017-08-29 15 18 44
screenshot 2017-08-29 15 20 44
screenshot 2017-08-29 15 32 25
screenshot 2017-08-29 15 37 26
screenshot 2017-08-31 07 38 17
screenshot 2017-08-31 07 38 41
screenshot 2017-08-31 07 41 12
screenshot 2017-08-31 07 41 31
screenshot 2017-08-31 07 47 01
screenshot 2017-08-31 07 51 58
screenshot 2017-08-31 07 53 45
screenshot 2017-08-31 08 20 17
screenshot 2017-08-31 08 30 37
screenshot 2017-08-31 09 05 06
screenshot 2017-08-31 09 07 37

Is the branch the correct one or shall I switch?

Cheers, Oskar

@OskarStark OskarStark changed the title use SymfonyStyle for output use SymfonyStyle for command output Aug 29, 2017
@OskarStark
Copy link
Contributor Author

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
Copy link
Contributor

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.',
]);

Copy link
Contributor Author

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!

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@lcobucci lcobucci left a 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;
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it

@lcobucci lcobucci added this to the 2.6.0 milestone Aug 30, 2017
@lcobucci
Copy link
Member

@OskarStark just a remark, please make sure you send test updates too.

@OskarStark
Copy link
Contributor Author

Ok, lets check the build 😄

@@ -36,21 +37,24 @@
class CollectionRegionCommand extends Command
{
/**
* @var SymfonyStyle
*/
protected $ui;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SymfonyStyle|null

@OskarStark
Copy link
Contributor Author

Hmm, this is a bit strange.
on my local machine, all tests are running, if my shell is big, if i minimize it it delivers the same error results like travis:

5) Doctrine\Tests\ORM\Tools\Console\Command\ClearCacheEntityRegionCommandTest::testClearCacheEntryName
Failed asserting that '\n
 // Clearing second-level cache entry for entity                                \n
 // "Doctrine\Tests\Models\Cache\Country" identified by                         \n
 // "1"                                                                         \n
\n
' contains " // Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by".

The SymfonyStyle add line breaks if needed.

any idea @Ocramius @javiereguiluz ?

@OskarStark
Copy link
Contributor Author

OskarStark commented Sep 27, 2017

@OskarStark
Copy link
Contributor Author

lets check if 142055c makes travis happy 🎉

@OskarStark
Copy link
Contributor Author

OskarStark commented Sep 27, 2017

Fails:

oskar.stark:~/dev/misc/doctrine2 (symfony-style)$ env COLUMNS=10 php -d memory_limit=-1 vendor/bin/phpunit --group=test
PHPUnit 6.4-ga1b5663a4 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.8
Configuration: /Users/oskar.stark/dev/misc/doctrine2/phpunit.xml.dist

.F                                                                  2 / 2 (100%)

Time: 484 ms, Memory: 40.00MB

There was 1 failure:

1) Doctrine\Tests\ORM\Tools\Console\Command\ClearCacheCollectionRegionCommandTest::testClearByOwnerEntityClassName
Failed asserting that '\n
 // Cleari\n
 // ng    \n
 // second\n
 // -level\n
 // cache \n
 // for   \n
 // collec\n
 // tion  \n
 //       \n
 // "Doctr\n
 // ine\Te\n
 // sts\Mo\n
 // dels\C\n
 // ache\S\n
 // tate#c\n
 // ities"\n
 // </info\n
 // >     \n
\n
' contains " // Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"".

/Users/oskar.stark/dev/misc/doctrine2/tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheCollectionRegionCommandTest.php:79

FAILURES!
Tests: 2, Assertions: 6, Failures: 1.

works:

oskar.stark:~/dev/misc/doctrine2 (symfony-style)$ env COLUMNS=120 php -d memory_limit=-1 vendor/bin/phpunit --group=test
PHPUnit 6.4-ga1b5663a4 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.8
Configuration: /Users/oskar.stark/dev/misc/doctrine2/phpunit.xml.dist

..                                                                  2 / 2 (100%)

Time: 474 ms, Memory: 40.00MB

OK (2 tests, 6 assertions)

@OskarStark
Copy link
Contributor Author

OskarStark commented Sep 27, 2017

Looks like 2 travis builds are still failing.... I don't know why.

Scrutinizer tests pass, after setting the COLUMNS env in .scrutinizer.yml

@OskarStark
Copy link
Contributor Author

https://github.com/doctrine/doctrine2/pull/6655/files#diff-354f30a63fb0907d4ad57269548329e3R12 fixes most of the travis builds, but 7.1 and 7.2 builds are still failing and I don't know why 😕 ❗️

@OskarStark
Copy link
Contributor Author

I rebased my branch, but don't know if travis is working now

@OskarStark
Copy link
Contributor Author

The 7.1 and 7.2 are failing if there is a custom MYSQL_VERSION set.
Looks like the COLUMNS env var is ignored, do you spawn any sub commands or sth like this, where the COLUMNS env var is not used anymore?

At the start of the build, the COLUMNS env var is exported
screenshot 2017-11-09 08 28 00

@OskarStark
Copy link
Contributor Author

any news?

@OskarStark
Copy link
Contributor Author

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

Copy link
Member

@Ocramius Ocramius left a 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

@lcobucci
Copy link
Member

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

@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...

@greg0ire
Copy link
Member

Other similarity between failing jobs: sudo: required

@OskarStark
Copy link
Contributor Author

damn, nothing is working 👎

@greg0ire
Copy link
Member

You could try to add sudo: required to another build to see if this it what causes the problem

@OskarStark
Copy link
Contributor Author

updated

@greg0ire
Copy link
Member

Looks like it is! That's progress 👍

@OskarStark
Copy link
Contributor Author

there are some parts of the code that are not being covered by tests, can you please check that? https://scrutinizer-ci.com/g/doctrine/doctrine2/inspections/cf59ead0-6eb9-4a28-b114-91d5328ba6e0/code-structure/test-coverage might be helpful

I will have a look

You're formatting some parts of the code in the same commit of your changes, that's a bit confusing to review (specially via mobile 😂), can you please revert those changes or split them into a different commit?

damn, i did before, but squashed all commits, thought this was already done 😞
Shall I rework the PR and split everything in different commits?

there're some additions that don't follow our code standards (like the spacing before and after the negation operator), can you please check that?

ofc, I will check, do you have a tool for that like StyleCi or a PHP-CS-Fixer config?

I think you forgot to define the constant in phpunit.xml.dist

done

@lcobucci
Copy link
Member

Shall I rework the PR and split everything in different commits?

I think it's fine to have 2 commits one that formats the old code and one that introduces SymfonyStyle, it should be simple to do that with reverting (soft) your commit and using git add -p but if I can help you on that later.

ofc, I will check, do you have a tool for that like StyleCi or a PHP-CS-Fixer config?

Yes, we use phpcs but we haven't configured it for the ORM yet 😭

@OskarStark
Copy link
Contributor Author

I think it's fine to have 2 commits one that formats the old code and one that introduces SymfonyStyle, it should be simple to do that with reverting (soft) your commit and using git add -p but if I can help you on that later.

don't worry, I will do it, but how to proceed with Scrutinizer? set COLUMNS or not?

Yes, we use phpcs but we haven't configured it for the ORM yet 😭

ok, i checked for the space before and after !

@lcobucci
Copy link
Member

don't worry, I will do it, but how to proceed with Scrutinizer?

@OskarStark I've merged the scrutinizer config to not run the tests there, please rebase your branch to sync with master

set COLUMNS or not?

Don't change anything on scrutinizer config =)

@OskarStark
Copy link
Contributor Author

OskarStark commented Nov 23, 2017

@OskarStark I've merged the scrutinizer config to not run the tests there, please rebase your branch to sync with master

rebased and splitted my commits

Copy link
Member

@lcobucci lcobucci left a 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) {
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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()));
Copy link
Member

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([
Copy link
Member

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([
Copy link
Member

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.');
Copy link
Member

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?

@lcobucci
Copy link
Member

lcobucci commented Nov 23, 2017

@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!

@OskarStark
Copy link
Contributor Author

OskarStark commented Nov 23, 2017

@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 😄

  • I added 2 tests for InfoCommand in a separate Command
  • I switched from $this->assert* to self::assert* in a separate commit
  • I removed all setDefinition() calls and replaced them by addOption() and addArgument() in a separate commit
  • I rebased my branch
  • I will now write a test for GenerateRepositoriesCommand

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()
Copy link
Contributor Author

@OskarStark OskarStark Nov 23, 2017

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 HelperSetwith 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

Copy link
Member

@lcobucci lcobucci Nov 23, 2017

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)

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@OskarStark
Copy link
Contributor Author

I will keep the separate commits, let me know if I should squash some of them together! 👍

Copy link
Member

@lcobucci lcobucci left a 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;
Copy link
Member

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(
Copy link
Member

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

OskarStark and others added 4 commits November 24, 2017 01:20
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*`).
@lcobucci lcobucci self-assigned this Nov 24, 2017
@lcobucci lcobucci merged commit b47a39b into doctrine:master Nov 24, 2017
@lcobucci
Copy link
Member

@OskarStark 🚢!

Thanks a lot for your contribution (and patience)!!

@lcobucci lcobucci changed the title use SymfonyStyle for command output Use SymfonyStyle for command output Nov 24, 2017
@OskarStark
Copy link
Contributor Author

Yeah, finally 😃 🎉 🍾

Thank you for your detailed feedback!

@OskarStark OskarStark deleted the symfony-style branch November 24, 2017 06:22
@hiddewie
Copy link

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants