Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WIP #25825: Add a failing test to demonstrate bug introduced in #24987. #25852

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

Closed
Closed
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
68 changes: 64 additions & 4 deletions 68 src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,76 @@ public function testGetFirstArgument()
$this->assertEquals('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
}

public function testHasParameterOption()
public function testFailingHasParameterOptionTest1()
{
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
$input = new ArgvInput(array('cli.php', '-etest'));

// CONTROL: We should not be calling 'bind' in the hasParameterOption test;
// this is here temporarily to demonstrate that -etest is interpreted as --example=test
$input->bind(new InputDefinition(array(new InputOption('example', 'e', InputOption::VALUE_REQUIRED))));
// [A]
$this->assertEquals(array('example' => 'test'), $input->getOptions(), 'CONTROL: the short option "e" has value "test".');

// [B] Failing test: $input has '-etest', which is the same as --example=test,
// but 'hasParameterOption' thinks that there is a '-s', because it interprets
// the short option as the combination of '-e -t -e -s -t'. This is incorrect,
// but hasParameterOption cannot use the InputDefinition, so it does not know this.
$this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');
}

public function testFailingHasParameterOptionTest2()
{
$input = new ArgvInput(array('cli.php', '-fh'));
// [C] Historically, the test below was not supported. This is the use-case
// that #24987 aimed to fix.
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
// [D] Another example of a use-case that #24987 aimed to fix. However, the
// implemented solution is not accurate, because hasParameterOption does
// not know if the previous short option, -f, takes a value or not. If
// -f takes a value, then -fh does NOT include -h. Otherwise it does.
$this->assertTrue($input->hasParameterOption('-h'), '->hasParameterOption() returns true if the given short option is in the raw input');
// [E] Historically, this test would pass; however, it is a bit odd. Does
// it mean "commandline contains both -f AND -h"? If so, should this
// also pass for 'cli.php -f -h'?
// It seems like it would be reasonable to not support this use-case,
// and require folks to use $input->hasParameterOption('-f') && $input->hasParameterOption('-h')
$this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
// [F] Failing test: If -fh is supported, then -hf should also work.
// It seems reasonable to not support this (or '-fh').
$this->assertTrue($input->hasParameterOption('-hf'), '->hasParameterOption() returns true if the given short option is in the raw input');
}

public function testFailingHasParameterOptionTest3()
{
$input = new ArgvInput(array('cli.php', '-f', '-h'));
// [G] As discussed above, if hasParameterOption('-fh') is supported for
// 'cli.php -f -h', then it seems it should also be supported
// for 'cli.php -f -h'.
// It seems reasonable to not support this.
$this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
}

public function testFailingHasParameterOptionTest4()
{
$input = new ArgvInput(array('cli.php', '-e=test'));
$this->assertFalse($input->hasParameterOption('-s'), '->hasParameterOption() returns true if the given short option is in the raw input');

// CONTROL: We should not be calling 'bind' in the hasParameterOption test;
// this is here temporarily to demonstrate that -etest is interpreted as --example=test
$input->bind(new InputDefinition(array(new InputOption('example', 'e', InputOption::VALUE_REQUIRED))));
// [H]
$this->assertEquals(array('example' => '=test'), $input->getOptions(), 'CONTROL: the short option "e" has value "test".');

// [I] Failing test: $input has '-e=test', which is the same as --example="=test",
// but 'getParameterOption' gets confused by the '=' and thinks that the value is
// only 'test'. This is always wrong, regardless of whether the short option has
// a value or not.
$this->assertEquals('=test', $input->getParameterOption('-e'), '->getParameterOption() returns the value of the given short option in the raw input');
}

public function testHasParameterOption()
{
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');

$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.