-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow mocking output interface (#20)
- required for old symfony versions
- Loading branch information
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symblaze\Console; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
/** | ||
* Old versions of Symfony do not add return data types to the output interface. | ||
* This class is a workaround to allow mocking the output interface in tests. | ||
*/ | ||
final class LegacySymfonyStyle extends SymfonyStyle | ||
{ | ||
public function __construct(InputInterface $input) | ||
{ | ||
parent::__construct($input, new NullOutput()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symblaze\Console; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class StyleFactory | ||
{ | ||
public static function create(InputInterface $input, OutputInterface $output): SymfonyStyle | ||
{ | ||
return is_null($output->getFormatter()) ? | ||
new LegacySymfonyStyle($input) : | ||
new SymfonyStyle($input, $output); | ||
} | ||
} |