Skip to content

Commit

Permalink
chore: allow mocking output
Browse files Browse the repository at this point in the history
- for old symfony versions that don't type hint the `getFormatter()` method
  • Loading branch information
imdhemy committed Mar 28, 2024
1 parent b125d2d commit ff6443b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/IO/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Symblaze\Console\IO;

use Symfony\Component\Console\Formatter\NullOutputFormatter;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

Expand All @@ -18,9 +18,10 @@ class Output extends SymfonyStyle
{
public function __construct(InputInterface $input, OutputInterface $output)
{
$formatter = $output->getFormatter() ?? new NullOutputFormatter();
$output->setFormatter($formatter);

if (is_null($output->getFormatter())) {
$output = new NullOutput();
}

parent::__construct($input, $output);
}
}

0 comments on commit ff6443b

Please sign in to comment.