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

Revamp the CommandTester #219

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Revamp the CommandTester #219

wants to merge 2 commits into from

Conversation

theofidry
Copy link
Owner

@theofidry theofidry commented Dec 14, 2023

  • Update the documentation
  • Review the BC breaks
  • Add tests
  • Note that by default it allows to test both the output, error output and the combined output
  • Review the API difference with the Symfony CommandTester

Related to #217 and #192.

use Closure;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;

final class DefaultFormatterFactory implements OutputFormatterFactory
Copy link
Owner Author

Choose a reason for hiding this comment

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

review separately how to configure the formatter; review how it is possible in the tests (currently) or document the limitation

$this->outputs = $outputs;
}

private function doWrite(string $message, bool $newline): void
Copy link
Owner Author

Choose a reason for hiding this comment

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

to remove (dead code)

* @psalm-suppress PropertyNotSetInConstructor
*/
final class CommandTester extends SymfonyCommandTester
class CommandTester
Copy link
Owner Author

Choose a reason for hiding this comment

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

to review if final is desired or not

private BaseSymfonyCommand $command,
// See Symfony's Output::__construct()
// We use the same default values.
private array $inputs = [],
Copy link
Owner Author

Choose a reason for hiding this comment

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

add a test to ensure the defaults are the same as the Symfony's ones

*
* @param bool $normalize Whether to normalize end of lines to \n or not.
*/
public function getDisplay(bool $normalize = false): string
Copy link
Owner Author

Choose a reason for hiding this comment

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

part of the proposal, rather than going with display and error display like done in ZendStruck's ConsoleTest, I choose:

  • display: stdout + stderr
  • output: stdout
  • error output: stderr

(stdout and stderr are the "defaults", as technically you could configure different outputs).

return $this;
}

public function dump(): self
Copy link
Owner Author

Choose a reason for hiding this comment

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

to properly integrate it I just copy/pasted ZendStruck ConsoleTest's API
also add the licensing


private static function createOutput(OutputInterface $config): StreamOutput
{
$stream = fopen('php://memory', 'wb');
Copy link
Owner Author

Choose a reason for hiding this comment

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

to double check if b is desired or not and double check on Symfony's side too

*
* @param bool $normalize Whether to normalize end of lines to \n or not.
*/
public function getDisplay(bool $normalize = false): string
Copy link
Owner Author

Choose a reason for hiding this comment

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

we probably want more normalization options like it was previously offered (with $extraNormalizers) and/or leverage the DisplayNormalizer

*
* @param bool $normalize Whether to normalize end of lines to \n or not.
*/
public function getOutput(bool $normalize = false): string
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
public function getOutput(bool $normalize = false): string
public function getStandardOutput(bool $normalize = false): string

?

use function rewind;
use function stream_get_contents;

final class TestOutput implements ConsoleOutputInterface
Copy link
Owner Author

Choose a reason for hiding this comment

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

probably should be @internal

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

Successfully merging this pull request may close these issues.

1 participant