[Console] Allow redefinition of application options descriptions
This commit is contained in:
parent
8ce034fae0
commit
c7ab9ba7ec
@ -261,9 +261,9 @@ class InputDefinition
|
||||
*/
|
||||
public function addOption(InputOption $option)
|
||||
{
|
||||
if (isset($this->options[$option->getName()])) {
|
||||
if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
|
||||
throw new \LogicException(sprintf('An option named "%s" already exist.', $option->getName()));
|
||||
} elseif (isset($this->shortcuts[$option->getShortcut()])) {
|
||||
} elseif (isset($this->shortcuts[$option->getShortcut()]) && !$option->equals($this->options[$this->shortcuts[$option->getShortcut()]])) {
|
||||
throw new \LogicException(sprintf('An option with shortcut "%s" already exist.', $option->getShortcut()));
|
||||
}
|
||||
|
||||
|
@ -181,4 +181,21 @@ class InputOption
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given option equals this one
|
||||
*
|
||||
* @param InputOption $option option to compare
|
||||
* @return Boolean
|
||||
*/
|
||||
public function equals(InputOption $option)
|
||||
{
|
||||
return $option->getName() === $this->getName()
|
||||
&& $option->getShortcut() === $this->getShortcut()
|
||||
&& $option->getDefault() === $this->getDefault()
|
||||
&& $option->isArray() === $this->isArray()
|
||||
&& $option->isValueRequired() === $this->isValueRequired()
|
||||
&& $option->isValueOptional() === $this->isValueOptional()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -140,4 +140,27 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testEquals()
|
||||
{
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('foo', 'f', null, 'Alternative description');
|
||||
$this->assertTrue($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, 'Some description');
|
||||
$option2 = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, 'Some description', true);
|
||||
$this->assertFalse($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('bar', 'f', null, 'Some description');
|
||||
$this->assertFalse($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('foo', '', null, 'Some description');
|
||||
$this->assertFalse($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, 'Some description');
|
||||
$this->assertFalse($option->equals($option2));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user