Skip to content

Commit

Permalink
[minor] allow Symfony 6 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond authored Sep 13, 2021
1 parent 4d59b3b commit 997ee1f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ jobs:
matrix:
php: [7.4, 8.0]
stability: [hightest]
symfony: [4.4.*, 5.2.*, 5.3.*]
symfony: [4.4.*, 5.2.*, 5.3.*, 5.4.*]
include:
- php: 7.4
stability: lowest
symfony: '*'
- php: 8.0
stability: hightest
symfony: 6.0.*
steps:
- name: Checkout code
uses: actions/checkout@v2.3.3
Expand All @@ -28,9 +31,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install Symfony Flex
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main
tools: flex

- name: Install dependencies
uses: ramsey/composer-install@v1
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
],
"require": {
"php": ">=7.4",
"symfony/console": "^4.4.5|^5.0"
"symfony/console": "^4.4.5|^5.0|^6.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.0",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/phpunit-bridge": "^5.2"
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/phpunit-bridge": "^5.3"
},
"config": {
"preferred-install": "dist",
Expand All @@ -29,5 +29,7 @@
},
"autoload-dev": {
"psr-4": { "Zenstruck\\Console\\Test\\Tests\\": "tests/" }
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
26 changes: 13 additions & 13 deletions src/CommandTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,53 @@ final class CommandTester
use TesterTrait;

private Command $command;
private InputInterface $input;
private InputInterface $testInput;

public function __construct(Command $command, InputInterface $input)
{
$this->command = $command;
$this->input = $input;
$this->testInput = $input;
}

public function execute(bool $splitStreams): CommandResult
{
$this->input->setInteractive(false);
$this->testInput->setInteractive(false);

if ($this->inputs) {
$this->input->setStream(self::createStream($this->inputs));
$this->input->setInteractive(true);
$this->testInput->setStream(self::createStream($this->inputs));
$this->testInput->setInteractive(true);
}

if (true === $this->input->hasParameterOption(['--no-interaction', '-n'], true)) {
$this->input->setInteractive(false);
if (true === $this->testInput->hasParameterOption(['--no-interaction', '-n'], true)) {
$this->testInput->setInteractive(false);
}

$this->initOutput([
'decorated' => true === $this->input->hasParameterOption(['--ansi'], true),
'decorated' => true === $this->testInput->hasParameterOption(['--ansi'], true),
'verbosity' => $this->verbosity(),
'capture_stderr_separately' => $splitStreams,
]);

$statusCode = $this->command->run($this->input, $this->output);
$statusCode = $this->command->run($this->testInput, $this->output);

return new CommandResult($statusCode, $this->getDisplay(), $splitStreams ? $this->getErrorOutput() : '');
}

private function verbosity(): int
{
if (true === $this->input->hasParameterOption(['--quiet', '-q'], true)) {
if (true === $this->testInput->hasParameterOption(['--quiet', '-q'], true)) {
return OutputInterface::VERBOSITY_QUIET;
}

if ($this->input->hasParameterOption('-vvv', true) || $this->input->hasParameterOption('--verbose=3', true) || 3 === $this->input->getParameterOption('--verbose', false, true)) {
if ($this->testInput->hasParameterOption('-vvv', true) || $this->testInput->hasParameterOption('--verbose=3', true) || 3 === $this->testInput->getParameterOption('--verbose', false, true)) {
return OutputInterface::VERBOSITY_DEBUG;
}

if ($this->input->hasParameterOption('-vv', true) || $this->input->hasParameterOption('--verbose=2', true) || 2 === $this->input->getParameterOption('--verbose', false, true)) {
if ($this->testInput->hasParameterOption('-vv', true) || $this->testInput->hasParameterOption('--verbose=2', true) || 2 === $this->testInput->getParameterOption('--verbose', false, true)) {
return OutputInterface::VERBOSITY_VERY_VERBOSE;
}

if ($this->input->hasParameterOption('-v', true) || $this->input->hasParameterOption('--verbose=1', true) || $this->input->hasParameterOption('--verbose', true) || $this->input->getParameterOption('--verbose', false, true)) {
if ($this->testInput->hasParameterOption('-v', true) || $this->testInput->hasParameterOption('--verbose=1', true) || $this->testInput->hasParameterOption('--verbose', true) || $this->testInput->getParameterOption('--verbose', false, true)) {
return OutputInterface::VERBOSITY_VERBOSE;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/FixtureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function configure(): void
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;

Expand Down
3 changes: 1 addition & 2 deletions tests/Fixture/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

/**
* @author Kevin Bond <kevinbond@gmail.com>
Expand Down Expand Up @@ -37,7 +36,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
]);
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
protected function configureRoutes($routes): void
{
// noop
}
Expand Down

0 comments on commit 997ee1f

Please sign in to comment.