-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Additional validation of mode in InputArgument
and InputOption
#52055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jnoordsij
wants to merge
4
commits into
symfony:7.4
Choose a base branch
from
jnoordsij:console-input-mode-validation
base: 7.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b69c2eb
Disallow setting both REQUIRED and OPTIONAL on InputArgument
jnoordsij fbd2554
Disallow setting combinations of NONE, REQUIRED and OPTIONAL on Input…
jnoordsij 251b242
Add entries to CHANGELOG and UPGRADE-6.4 for deprecated modes on Inpu…
jnoordsij 2262675
Improve codestyle for mode check in InputOption
jnoordsij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Console\Tests\Input; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\Console\Completion\CompletionInput; | ||
use Symfony\Component\Console\Completion\CompletionSuggestions; | ||
use Symfony\Component\Console\Completion\Suggestion; | ||
|
@@ -20,6 +21,8 @@ | |
|
||
class InputOptionTest extends TestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
public function testConstructor() | ||
{ | ||
$option = new InputOption('foo'); | ||
|
@@ -69,9 +72,9 @@ public function testModes() | |
$this->assertFalse($option->isValueOptional(), '__construct() gives a "InputOption::VALUE_NONE" mode by default'); | ||
|
||
$option = new InputOption('foo', 'f', null); | ||
$this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode'); | ||
$this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode'); | ||
$this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode'); | ||
$this->assertFalse($option->acceptValue(), '__construct() gives a "InputOption::VALUE_NONE" mode by default'); | ||
$this->assertFalse($option->isValueRequired(), '__construct() gives a "InputOption::VALUE_NONE" mode by default'); | ||
$this->assertFalse($option->isValueOptional(), '__construct() gives a "InputOption::VALUE_NONE" mode by default'); | ||
|
||
$option = new InputOption('foo', 'f', InputOption::VALUE_NONE); | ||
$this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode'); | ||
|
@@ -97,6 +100,46 @@ public function testInvalidModes() | |
new InputOption('foo', 'f', '-1'); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testCombiningNoneAndRequiredModeIsInvalid() | ||
{ | ||
$this->expectDeprecation('Since symfony/console 6.4: InputOption mode should be either none, required or optional.'); | ||
|
||
new InputOption('foo', 'f', InputOption::VALUE_NONE | InputOption::VALUE_REQUIRED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered using a data provider to reduce repetition? |
||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testCombiningNoneAndOptionalModeIsInvalid() | ||
{ | ||
$this->expectDeprecation('Since symfony/console 6.4: InputOption mode should be either none, required or optional.'); | ||
|
||
new InputOption('foo', 'f', InputOption::VALUE_NONE | InputOption::VALUE_OPTIONAL); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testCombiningRequiredAndOptionalModeIsInvalid() | ||
{ | ||
$this->expectDeprecation('Since symfony/console 6.4: InputOption mode should be either none, required or optional.'); | ||
|
||
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_OPTIONAL); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
public function testCombiningNoneRequiredAndOptionalModeIsInvalid() | ||
{ | ||
$this->expectDeprecation('Since symfony/console 6.4: InputOption mode should be either none, required or optional.'); | ||
|
||
new InputOption('foo', 'f', InputOption::VALUE_NONE | InputOption::VALUE_REQUIRED | InputOption::VALUE_OPTIONAL); | ||
} | ||
|
||
public function testEmptyNameIsInvalid() | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add the option name to the deprecation message. That would help to find where the change need to be done when our tools don't provide the backtrace of the trigger.