8000 [Console] Added three state long option by ocke · Pull Request #11883 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Added three state long option #11883

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
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
written tests
  • Loading branch information
Olaf Kwant committed Sep 10, 2014
commit 625a4ad509954f9ab126d2a97d4d5dc94f6886e2
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ public function provideOptions()
array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)),
array('foo' => 'bbar', 'bar' => null),
'->parse() parses short options when they are aggregated as a single one and one of them takes a value'
),
array(
array('cli.php'),
array(new InputOption('foo', 'f', InputOption::VALUE_TERNARY)),
array('foo' => false),
'->parse() parses undefined ternary long option'
),
array(
array('cli.php', '--foo'),
array(new InputOption('foo', 'f', InputOption::VALUE_TERNARY)),
array('foo' => null),
'->parse() parses ternary long option without a value'
),
array(
array('cli.php', '--foo=test'),
array(new InputOption('foo', 'f', InputOption::VALUE_TERNARY)),
array('foo' => 'test'),
'->parse() parses ternary long option with a value'
)
);
}
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/Console/Tests/Input/InputOptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function testModes()
$this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
$this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
$this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');

$option = new InputOption('foo', 'f', InputOption::VALUE_TERNARY);
$this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_TERNARY" as its mode');
$this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_TERNARY" as its mode');
$this->assertTrue($option->isValueTernary(), '__construct() can take "InputOption::VALUE_TERNARY" as its mode');
}

/**
Expand Down Expand Up @@ -144,6 +149,28 @@ public function testGetDefault()

$option = new InputOption('foo', null, InputOption::VALUE_NONE);
$this->assertFalse($option->getDefault(), '->getDefault() returns false if the option does not take a value');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY);
$this->assertFalse($option->getDefault(), '->getDefault() returns false if the option does not take a value');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY);
$this->assertEquals(false, $option->getDefault(), '->getDefault() returns false');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY, '', 'default');
$this->assertEquals(false, $option->getDefault(), '->getDefault() returns false');
}


public function testGetSetDefault()
{
$option = new InputOption('foo');
$this->assertEquals(false, $option->getSetDefault(), '->getDefault() returns false');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY);
$this->assertEquals(null, $option->getSetDefault(), '->getDefault() returns null if the option does not have a value');

$option = new InputOption('foo', null, InputOption::VALUE_TERNARY, '', 'default');
$this->assertEquals('default', $option->getSetDefault(), '->getDefault() returns the default value');
}

public function testSetDefault()
Expand Down
0