Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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