-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[SymfonyStyle] Unable to test a command in phpUnit #26885
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
Comments
You are using |
I will try this today, and will tell you the result, thanks. |
I have more news: i updated the Command to send an exit code instead of use the exit() function from php and i updated the phpUnit test for it Now i can see correctly phpUnit information, but in my option there is a trouble :
This is the test i have done to try to find where the bug is:
This is the main menu output which ask for user input. After nothing is outputed
i tried something simplier to identify where something wrong happend:
when i do setInputs([0]), and then try to display output, i have the menu but not the result of the function "echo a basic message". I hope there is enought information to understand what s could be wrong. |
Even without Symfony style i get a strange behavior:
Result:
|
For your last example, your command is asking two questions but only one is answered by your test. Calling I'll give a try to your previous examples today. |
I tryed like this and the phpunit test exited without any information, only the "BEFORE ?" is outputed in phpunit By the way the documentation say that each question should have a setInputs: from https://symfony.com/doc/current/components/console/helpers/questionhelper.html
|
@chalasr Same problem. https://travis-ci.org/Gemorroj/console-phar-example/builds/426048579 |
@Gemorroj that's a bug, using |
@chalasr Yes, I did not have time to fully understand, but it seems there https://github.com/symfony/console/blob/4.1/Helper/SymfonyQuestionHelper.php#L59-L61 should be something like this: $choices = $question->getChoices();
$defaultValue = \array_search($default, $choices, true);
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$defaultValue])); |
…oice value as default (chalasr) This PR was merged into the 2.8 branch. Discussion ---------- [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26885 | License | MIT | Doc PR | n/a There is an inconsistency between `SymfonyStyle::askQuestion(new ChoiceQuestion(...))` and `SymfonyStyle::choice(...)`, the former does not support to have a choice value as default instead of a choice key while the latter handles both. This is causing an `undefined index` notice breaking interactive command testing, fixed here. Commits ------- c51dda0 [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
…oice value as default (chalasr) This PR was merged into the 2.8 branch. Discussion ---------- [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#26885 | License | MIT | Doc PR | n/a There is an inconsistency between `SymfonyStyle::askQuestion(new ChoiceQuestion(...))` and `SymfonyStyle::choice(...)`, the former does not support to have a choice value as default instead of a choice key while the latter handles both. This is causing an `undefined index` notice breaking interactive command testing, fixed here. Commits ------- c51dda0 [Console] Fix SymfonyQuestionHelper::askQuestion() with choice value as default
Uh oh!
There was an error while loading. Please reload this page.
Hi, iam trying to test a Command using symfony style
https://github.com/FroggDev/Symfony_StockManager/blob/master/src/Command/UserManager.php
I tried a lot of things without success in phpUnit with KernelTestCase.
This is the version of the code i am using to test the command:
Based on https://symfony.com/doc/current/components/console/helpers/questionhelper.html
The string "Before" is displayed but after the excecute no more output are displayed.
Even any phpUnit output.
Is there anyway to solve this trouble ?
Thanks
The text was updated successfully, but these errors were encountered: