Skip to content

Commit

Permalink
Fix: runSymfonyConsoleCommand ignores specific options (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
TavoNiievez authored Mar 18, 2024
1 parent e45d5af commit 3bbf45c
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/Codeception/Module/Symfony/ConsoleAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Codeception\Module\Symfony;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

Expand Down Expand Up @@ -33,8 +34,10 @@ public function runSymfonyConsoleCommand(string $command, array $parameters = []
$commandTester = new CommandTester($consoleCommand);
$commandTester->setInputs($consoleInputs);

$parameters = ['command' => $command] + $parameters;
$exitCode = $commandTester->execute($parameters);
$input = ['command' => $command] + $parameters;
$options = $this->configureOptions($parameters);

$exitCode = $commandTester->execute($input, $options);
$output = $commandTester->getDisplay();

$this->assertSame(
Expand All @@ -51,6 +54,49 @@ public function runSymfonyConsoleCommand(string $command, array $parameters = []
return $output;
}

private function configureOptions(array $parameters): array
{
$options = [];

if (in_array('--ansi', $parameters, true)) {
$options['decorated'] = true;
} elseif (in_array('--no-ansi', $parameters, true)) {
$options['decorated'] = false;
}

if (in_array('--no-interaction', $parameters, true) || in_array('-n', $parameters, true)) {
$options['interactive'] = false;
}

if (in_array('--quiet', $parameters, true) || in_array('-q', $parameters, true)) {
$options['verbosity'] = OutputInterface::VERBOSITY_QUIET;
$options['interactive'] = false;
}

if (
in_array('-vvv', $parameters, true) ||
in_array('--verbose=3', $parameters, true) ||
(isset($parameters["--verbose"]) && $parameters["--verbose"] === 3)
) {
$options['verbosity'] = OutputInterface::VERBOSITY_DEBUG;
} elseif (
in_array('-vv', $parameters, true) ||
in_array('--verbose=2', $parameters, true) ||
(isset($parameters["--verbose"]) && $parameters["--verbose"] === 2)
) {
$options['verbosity'] = OutputInterface::VERBOSITY_VERY_VERBOSE;
} elseif (
in_array('-v', $parameters, true) ||
in_array('--verbose=1', $parameters, true) ||
in_array('--verbose', $parameters, true) ||
(isset($parameters["--verbose"]) && $parameters["--verbose"] === 1)
) {
$options['verbosity'] = OutputInterface::VERBOSITY_VERBOSE;
}

return $options;
}

protected function grabKernelService(): KernelInterface
{
return $this->grabService('kernel');
Expand Down

0 comments on commit 3bbf45c

Please sign in to comment.