Skip to content

Commit

Permalink
[console] Fix console handler with named arguments and add more tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeboer committed Jan 8, 2023
1 parent 0ef1bf4 commit 83ede57
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Handler/ConsoleHandler.php
Expand Up @@ -264,7 +264,7 @@ private static function normalizeParams(array $params, array $args): array

$key = array_search($name, $params);
Assert::integer($key);
$params = array_slice($params, $key + 1);
unset($params[$key]);
} else {
$name = array_shift($params);
}
Expand Down
Expand Up @@ -8,6 +8,7 @@ Feature: ConsoleArgument named arguments with PHP8
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
"""
Expand Down Expand Up @@ -36,3 +37,28 @@ Feature: ConsoleArgument named arguments with PHP8
| Type | Message |
| Trace | $argument: string |
And I see no other errors

Scenario: Assert adding console argument with only named arguments works as expected
Given I have the following code
"""
class MyCommand extends Command
{
protected function configure(): void
{
$this->addArgument(name: 'test', description: 'foo', mode: InputArgument::OPTIONAL, default: 'test');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @psalm-trace $argument */
$argument = $input->getArgument('test');
return 0;
}
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| Trace | $argument: string |
And I see no other errors
31 changes: 31 additions & 0 deletions tests/acceptance/acceptance/console/ConsoleOptionNamedArgs.feature
Expand Up @@ -37,3 +37,34 @@ Feature: ConsoleOption named arguments with PHP8
| Type | Message |
| Trace | $string: string |
And I see no other errors

Scenario: Assert adding options with only named arguments works as expected
Given I have the following code
"""
class MyCommand extends Command
{
public function configure(): void
{
$this->addOption(
name: 'test',
mode: InputOption::VALUE_REQUIRED,
description: 'foo',
shortcut: 't',
default: 'test'
);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
/** @psalm-trace $string */
$string = $input->getOption('test');
return 0;
}
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| Trace | $string: string |
And I see no other errors

0 comments on commit 83ede57

Please sign in to comment.