-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Console] Allow to test the different streams at the same time #61494
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
base: 7.4
Are you sure you want to change the base?
Conversation
on execute($options) # Conflicts: # src/Symfony/Component/Console/Tester/CommandTester.php
@@ -74,6 +76,7 @@ protected function doWrite(string $message, bool $newline): void | |||
fflush($this->stream); | |||
} | |||
|
|||
// TODO: should be public & static? | |||
/** |
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 piece of code is implemented and use in several places. I wonder if it would make sense to either expose it as a static public utility or extract it and re-use that extracted utility here.
But irrelevant to the MR, to clean up
public function __construct( | ||
callable|Command $command, | ||
callable|Command $command, | ||
// TODO: to discuss if we want it in the constructor with the setters or only in the ::run() method |
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.
open question
]; | ||
} | ||
|
||
// TODO: to discuss if we want fluent setters |
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.
open question (note that if we have them in the constructor instead, we do not need those setters).
In general I am not a fan of fluent setters, but in the context of such test utilities it does make it a bit nicer. It's very subjective though
@@ -49,29 +123,90 @@ public function __construct( | |||
*/ | |||
public function execute(array $input, array $options = []): int |
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.
to deprecate in favour of the ::run()
IMO
} | ||
|
||
// TODO: here we need to pass the result first if we want to keep some arguments optional. | ||
// Not wanting this is an argument for having the assertions in the ExecutionResult instead. |
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.
If we want to keep the approach of having traits in the test cases, then I think this trait makes sense. Otherwise it would make more sense to have this as part of ExecutionResult
IMO
/** | ||
* Collection of output normalizers | ||
*/ | ||
final class OutputNormalizers |
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.
strictly speaking not needed for the purpose of the MR so could be scrapped. I otherwise thought it would be interesting to have a dedicated re-usable utility rather than private methods left and right.
The application tester should also be adapted |
Currently testing a command looks like this:
However, sometimes it is important to test not just the combined output of the
command, but the stdout and stderr streams separately. One can do so using the
capture_stderr_separately
option:It works well. However, you know are testing two separate outputs. If the output
is important to you and you want to make sure things are displayed correctly to
the user, not just in each individual streams, you need to have both tests.
It is unnecessarily tedious. Instead, this PR proposes to expose and output that
offers both options at the same time.
This is the general spirit of this MR. Unfortunately I'm easily distracted, so I picked up a few things on the way which make sense as a whole but maybe should be left out for now.