[Command] Changing the InputOption::PARAMETER_* constants to InputOption::VALUE_* to more accurately reflect that these constants refer to the value or lack of value assigned to a particular option (e.g. --verbose or --em=doctrine).

To keep language consistent, three methods were changed in InputOption:

 * `InputOption::acceptParameter()` -> `InputOption::acceptValue()`
 * `InputOption::isParameterRequired()` -> InputOption::isValueRequired()`
 * `InputOption::isParameterOptional()` -> `InputOption::isValueOptional()`

The InputDefinition::asXml() method was also modified to update the `accept_value` and `is_value_required` attributes.
This commit is contained in:
Ryan Weaver 2010-11-27 10:56:55 -06:00 committed by Fabien Potencier
parent 9c8cae24f8
commit 7efb4630b8
44 changed files with 184 additions and 184 deletions

View File

@ -31,7 +31,7 @@ class ClearMetadataCacheDoctrineCommand extends MetadataCommand
$this
->setName('doctrine:cache:clear-metadata')
->setDescription('Clear all metadata cache for a entity manager.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:cache:clear-metadata</info> command clears all metadata cache for the default entity manager:

View File

@ -31,7 +31,7 @@ class ClearQueryCacheDoctrineCommand extends QueryCommand
$this
->setName('doctrine:cache:clear-query')
->setDescription('Clear all query cache for a entity manager.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:cache:clear-query</info> command clears all query cache for the default entity manager:

View File

@ -31,7 +31,7 @@ class ClearResultCacheDoctrineCommand extends ResultCommand
$this
->setName('doctrine:cache:clear-result')
->setDescription('Clear result cache for a entity manager.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:cache:clear-result</info> command clears all result cache for the default entity manager:

View File

@ -32,7 +32,7 @@ class ConvertMappingDoctrineCommand extends ConvertMappingCommand
parent::configure();
$this
->setName('doctrine:mapping:convert')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:mapping:convert</info> command converts mapping information between supported formats:

View File

@ -34,7 +34,7 @@ class CreateDatabaseDoctrineCommand extends DoctrineCommand
$this
->setName('doctrine:database:create')
->setDescription('Create the configured databases.')
->addOption('connection', null, InputOption::PARAMETER_OPTIONAL, 'The connection to use for this command.')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:database:create</info> command creates the default connections database:

View File

@ -32,7 +32,7 @@ class CreateSchemaDoctrineCommand extends CreateCommand
$this
->setName('doctrine:schema:create')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:schema:create</info> command creates the default entity managers schema:

View File

@ -34,7 +34,7 @@ class DropDatabaseDoctrineCommand extends DoctrineCommand
$this
->setName('doctrine:database:drop')
->setDescription('Drop the configured databases.')
->addOption('connection', null, InputOption::PARAMETER_OPTIONAL, 'The connection to use for this command.')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:database:drop</info> command drops the default connections database:

View File

@ -32,7 +32,7 @@ class DropSchemaDoctrineCommand extends DropCommand
$this
->setName('doctrine:schema:drop')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:schema:drop</info> command drops the default entity managers schema:

View File

@ -32,7 +32,7 @@ class EnsureProductionSettingsDoctrineCommand extends EnsureProductionSettingsCo
$this
->setName('doctrine:ensure-production-settings')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:cache:clear-metadata</info> command clears all metadata cache for the default entity manager:

View File

@ -32,8 +32,8 @@ class GenerateEntitiesDoctrineCommand extends DoctrineCommand
$this
->setName('doctrine:generate:entities')
->setDescription('Generate entity classes and method stubs from your mapping information.')
->addOption('bundle', null, InputOption::PARAMETER_OPTIONAL, 'The bundle to initialize the entity or entities in.')
->addOption('entity', null, InputOption::PARAMETER_OPTIONAL, 'The entity class to initialize (requires bundle parameter).')
->addOption('bundle', null, InputOption::VALUE_OPTIONAL, 'The bundle to initialize the entity or entities in.')
->addOption('entity', null, InputOption::VALUE_OPTIONAL, 'The entity class to initialize (requires bundle parameter).')
->setHelp(<<<EOT
The <info>doctrine:generate:entities</info> command generates entity classes and method stubs from your mapping information:

View File

@ -35,8 +35,8 @@ class GenerateEntityDoctrineCommand extends DoctrineCommand
->setDescription('Generate a new Doctrine entity inside a bundle.')
->addArgument('bundle', null, InputArgument::REQUIRED, 'The bundle to initialize the entity in.')
->addArgument('entity', null, InputArgument::REQUIRED, 'The entity class to initialize.')
->addOption('mapping-type', null, InputOption::PARAMETER_OPTIONAL, 'The mapping type to to use for the entity.')
->addOption('fields', null, InputOption::PARAMETER_OPTIONAL, 'The fields to create with the new entity.')
->addOption('mapping-type', null, InputOption::VALUE_OPTIONAL, 'The mapping type to to use for the entity.')
->addOption('fields', null, InputOption::VALUE_OPTIONAL, 'The fields to create with the new entity.')
->setHelp(<<<EOT
The <info>doctrine:generate:entity</info> task initializes a new Doctrine entity inside a bundle:

View File

@ -32,7 +32,7 @@ class GenerateProxiesDoctrineCommand extends GenerateProxiesCommand
$this
->setName('doctrine:generate:proxies')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:generate:proxies</info> command generates proxy classes for your entities:

View File

@ -37,7 +37,7 @@ class ImportMappingDoctrineCommand extends DoctrineCommand
->setName('doctrine:mapping:import')
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to import the mapping information to.')
->addArgument('mapping-type', InputArgument::OPTIONAL, 'The mapping type to export the imported mapping information to.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setDescription('Import mapping information from an existing database.')
->setHelp(<<<EOT
The <info>doctrine:mapping:import</info> command imports mapping information from an existing database:

View File

@ -37,9 +37,9 @@ class LoadDataFixturesDoctrineCommand extends DoctrineCommand
$this
->setName('doctrine:data:load')
->setDescription('Load data fixtures to your database.')
->addOption('fixtures', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'The directory or file to load data fixtures from.')
->addOption('append', null, InputOption::PARAMETER_OPTIONAL, 'Whether or not to append the data fixtures.', false)
->addOption('em', null, InputOption::PARAMETER_REQUIRED, 'The entity manager to use for this command.')
->addOption('fixtures', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The directory or file to load data fixtures from.')
->addOption('append', null, InputOption::VALUE_OPTIONAL, 'Whether or not to append the data fixtures.', false)
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:data:load</info> command loads data fixtures from your bundles:

View File

@ -32,7 +32,7 @@ class RunDqlDoctrineCommand extends RunDqlCommand
$this
->setName('doctrine:query:dql')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:query:dql</info> command executes the given DQL query and outputs the results:

View File

@ -32,7 +32,7 @@ class RunSqlDoctrineCommand extends RunSqlCommand
$this
->setName('doctrine:query:sql')
->addOption('connection', null, InputOption::PARAMETER_OPTIONAL, 'The connection to use for this command.')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:query:sql</info> command executes the given DQL query and outputs the results:

View File

@ -32,7 +32,7 @@ class UpdateSchemaDoctrineCommand extends UpdateCommand
$this
->setName('doctrine:schema:update')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:schema:update</info> command updates the default entity managers schema:

View File

@ -31,8 +31,8 @@ class MigrationsDiffDoctrineCommand extends DiffCommand
$this
->setName('doctrine:migrations:diff')
->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('bundle', null, InputOption::VALUE_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
;
}

View File

@ -30,8 +30,8 @@ class MigrationsExecuteDoctrineCommand extends ExecuteCommand
$this
->setName('doctrine:migrations:execute')
->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('bundle', null, InputOption::VALUE_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
;
}

View File

@ -30,8 +30,8 @@ class MigrationsGenerateDoctrineCommand extends GenerateCommand
$this
->setName('doctrine:migrations:generate')
->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('bundle', null, InputOption::VALUE_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
;
}

View File

@ -30,8 +30,8 @@ class MigrationsMigrateDoctrineCommand extends MigrateCommand
$this
->setName('doctrine:migrations:migrate')
->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('bundle', null, InputOption::VALUE_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
;
}

View File

@ -30,8 +30,8 @@ class MigrationsStatusDoctrineCommand extends StatusCommand
$this
->setName('doctrine:migrations:status')
->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('bundle', null, InputOption::VALUE_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
;
}

View File

@ -30,8 +30,8 @@ class MigrationsVersionDoctrineCommand extends VersionCommand
$this
->setName('doctrine:migrations:version')
->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to use for this command.')
->addOption('bundle', null, InputOption::VALUE_REQUIRED, 'The bundle to load migrations configuration from.')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
;
}

View File

@ -22,7 +22,7 @@ class CreateSchemaDoctrineODMCommand extends CreateCommand
$this
->setName('doctrine:mongodb:schema:create')
->addOption('dm', null, InputOption::PARAMETER_REQUIRED, 'The document manager to use for this command.')
->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:mongodb:schema:create</info> command creates the default document manager's schema:

View File

@ -22,7 +22,7 @@ class DropSchemaDoctrineODMCommand extends DropCommand
$this
->setName('doctrine:mongodb:schema:drop')
->addOption('dm', null, InputOption::PARAMETER_REQUIRED, 'The document manager to use for this command.')
->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:mongodb:schema:drop</info> command drops the default document manager's schema:

View File

@ -37,9 +37,9 @@ class LoadDataFixturesDoctrineODMCommand extends DoctrineODMCommand
$this
->setName('doctrine:mongodb:data:load')
->setDescription('Load data fixtures to your database.')
->addOption('fixtures', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'The directory or file to load data fixtures from.')
->addOption('append', null, InputOption::PARAMETER_OPTIONAL, 'Whether or not to append the data fixtures.', false)
->addOption('dm', null, InputOption::PARAMETER_REQUIRED, 'The document manager to use for this command.')
->addOption('fixtures', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The directory or file to load data fixtures from.')
->addOption('append', null, InputOption::VALUE_OPTIONAL, 'Whether or not to append the data fixtures.', false)
->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:mongodb:data:load</info> command loads data fixtures from your bundles:

View File

@ -34,7 +34,7 @@ class AssetsInstallCommand extends Command
->setDefinition(array(
new InputArgument('target', InputArgument::REQUIRED, 'The target directory'),
))
->addOption('symlink', null, InputOption::PARAMETER_NONE, 'Symlinks the assets instead of copying it')
->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it')
->setName('assets:install')
;
}

View File

@ -35,7 +35,7 @@ class Application extends BaseApplication
parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName());
$this->definition->addOption(new InputOption('--shell', '-s', InputOption::PARAMETER_NONE, 'Launch the shell.'));
$this->definition->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.'));
if (!$this->kernel->isBooted()) {
$this->kernel->boot();

View File

@ -80,12 +80,12 @@ class Application
$this->definition = new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
new InputOption('--help', '-h', InputOption::PARAMETER_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::PARAMETER_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::PARAMETER_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::PARAMETER_NONE, 'Display this program version.'),
new InputOption('--ansi', '-a', InputOption::PARAMETER_NONE, 'Force ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::PARAMETER_NONE, 'Do not ask any interactive question.'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
new InputOption('--ansi', '-a', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
));
}

View File

@ -236,9 +236,9 @@ class Command
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param integer $mode The option mode: self::PARAMETER_REQUIRED, self::PARAMETER_NONE or self::PARAMETER_OPTIONAL
* @param integer $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or self::VALUE_NONE)
*
* @return Command The current instance
*/

View File

@ -37,7 +37,7 @@ class HelpCommand extends Command
$this
->setDefinition(array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
))
->setName('help')
->setAliases(array('?'))

View File

@ -33,7 +33,7 @@ class ListCommand extends Command
$this
->setDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
))
->setName('list')
->setDescription('Lists commands')

View File

@ -88,7 +88,7 @@ class ArgvInput extends Input
$name = substr($token, 1);
if (strlen($name) > 1) {
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptParameter()) {
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
// an option with a value (with no space)
$this->addShortOption($name[0], substr($name, 1));
} else {
@ -115,7 +115,7 @@ class ArgvInput extends Input
}
$option = $this->definition->getOptionForShortcut($name[$i]);
if ($option->acceptParameter()) {
if ($option->acceptValue()) {
$this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
break;
@ -190,7 +190,7 @@ class ArgvInput extends Input
$option = $this->definition->getOption($name);
if (null === $value && $option->acceptParameter()) {
if (null === $value && $option->acceptValue()) {
// if option accepts an optional or mandatory argument
// let's see if there is one provided
$next = array_shift($this->parsed);
@ -202,11 +202,11 @@ class ArgvInput extends Input
}
if (null === $value) {
if ($option->isParameterRequired()) {
if ($option->isValueRequired()) {
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
}
$value = $option->isParameterOptional() ? $option->getDefault() : true;
$value = $option->isValueOptional() ? $option->getDefault() : true;
}
$this->options[$name] = $value;

View File

@ -133,11 +133,11 @@ class ArrayInput extends Input
$option = $this->definition->getOption($name);
if (null === $value) {
if ($option->isParameterRequired()) {
if ($option->isValueRequired()) {
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
}
$value = $option->isParameterOptional() ? $option->getDefault() : true;
$value = $option->isValueOptional() ? $option->getDefault() : true;
}
$this->options[$name] = $value;

View File

@ -18,7 +18,7 @@ namespace Symfony\Component\Console\Input;
*
* $definition = new InputDefinition(array(
* new InputArgument('name', InputArgument::REQUIRED),
* new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED),
* new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
* ));
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
@ -347,7 +347,7 @@ class InputDefinition
$elements = array();
foreach ($this->getOptions() as $option) {
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
$elements[] = sprintf('['.($option->isParameterRequired() ? '%s--%s="..."' : ($option->isParameterOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
$elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
}
foreach ($this->getArguments() as $argument) {
@ -399,7 +399,7 @@ class InputDefinition
$text[] = '<comment>Options:</comment>';
foreach ($this->getOptions() as $option) {
if ($option->acceptParameter() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', is_array($option->getDefault()) ? str_replace("\n", '', print_r($option->getDefault(), true)): $option->getDefault());
} else {
$default = '';
@ -450,13 +450,13 @@ class InputDefinition
$optionsXML->appendChild($optionXML = $dom->createElement('option'));
$optionXML->setAttribute('name', '--'.$option->getName());
$optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
$optionXML->setAttribute('accept_parameter', $option->acceptParameter() ? 1 : 0);
$optionXML->setAttribute('is_parameter_required', $option->isParameterRequired() ? 1 : 0);
$optionXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
$optionXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
$optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
$optionXML->appendChild($descriptionXML = $dom->createElement('description'));
$descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
if ($option->acceptParameter()) {
if ($option->acceptValue()) {
$optionXML->appendChild($defaultsXML = $dom->createElement('defaults'));
$defaults = is_array($option->getDefault()) ? $option->getDefault() : ($option->getDefault() ? array($option->getDefault()) : array());
foreach ($defaults as $default) {

View File

@ -18,10 +18,10 @@ namespace Symfony\Component\Console\Input;
*/
class InputOption
{
const PARAMETER_NONE = 1;
const PARAMETER_REQUIRED = 2;
const PARAMETER_OPTIONAL = 4;
const PARAMETER_IS_ARRAY = 8;
const VALUE_NONE = 1;
const VALUE_REQUIRED = 2;
const VALUE_OPTIONAL = 4;
const VALUE_IS_ARRAY = 8;
protected $name;
protected $shortcut;
@ -34,9 +34,9 @@ class InputOption
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param integer $mode The option mode: self::PARAMETER_REQUIRED, self::PARAMETER_NONE or self::PARAMETER_OPTIONAL
* @param integer $mode The option mode: One of the VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
*
* @throws \InvalidArgumentException If option mode is invalid or incompatible
*/
@ -57,7 +57,7 @@ class InputOption
}
if (null === $mode) {
$mode = self::PARAMETER_NONE;
$mode = self::VALUE_NONE;
} else if (!is_int($mode) || $mode > 15) {
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
}
@ -67,8 +67,8 @@ class InputOption
$this->mode = $mode;
$this->description = $description;
if ($this->isArray() && !$this->acceptParameter()) {
throw new \InvalidArgumentException('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.');
if ($this->isArray() && !$this->acceptValue()) {
throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
}
$this->setDefault($default);
@ -95,43 +95,43 @@ class InputOption
}
/**
* Returns true if the option accept a parameter.
* Returns true if the option accepts a value.
*
* @return Boolean true if parameter mode is not self::PARAMETER_NONE, false otherwise
* @return Boolean true if value mode is not self::VALUE_NONE, false otherwise
*/
public function acceptParameter()
public function acceptValue()
{
return $this->isParameterRequired() || $this->isParameterOptional();
return $this->isValueRequired() || $this->isValueOptional();
}
/**
* Returns true if the option requires a parameter.
* Returns true if the option requires a value.
*
* @return Boolean true if parameter mode is self::PARAMETER_REQUIRED, false otherwise
* @return Boolean true if value mode is self::VALUE_REQUIRED, false otherwise
*/
public function isParameterRequired()
public function isValueRequired()
{
return self::PARAMETER_REQUIRED === (self::PARAMETER_REQUIRED & $this->mode);
return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
}
/**
* Returns true if the option takes an optional parameter.
* Returns true if the option takes an optional value.
*
* @return Boolean true if parameter mode is self::PARAMETER_OPTIONAL, false otherwise
* @return Boolean true if value mode is self::VALUE_OPTIONAL, false otherwise
*/
public function isParameterOptional()
public function isValueOptional()
{
return self::PARAMETER_OPTIONAL === (self::PARAMETER_OPTIONAL & $this->mode);
return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
}
/**
* Returns true if the option can take multiple values.
*
* @return Boolean true if mode is self::PARAMETER_IS_ARRAY, false otherwise
* @return Boolean true if mode is self::VALUE_IS_ARRAY, false otherwise
*/
public function isArray()
{
return self::PARAMETER_IS_ARRAY === (self::PARAMETER_IS_ARRAY & $this->mode);
return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
}
/**
@ -141,8 +141,8 @@ class InputOption
*/
public function setDefault($default = null)
{
if (self::PARAMETER_NONE === (self::PARAMETER_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::PARAMETER_NONE mode.');
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
}
if ($this->isArray()) {
@ -153,7 +153,7 @@ class InputOption
}
}
$this->default = $this->acceptParameter() ? $default : false;
$this->default = $this->acceptValue() ? $default : false;
}
/**

View File

@ -23,7 +23,7 @@
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output help as XML</description>
</option>
</options>
@ -50,7 +50,7 @@
</argument>
</arguments>
<options>
<option name="--xml" shortcut="" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output help as XML</description>
</option>
</options>

View File

@ -13,22 +13,22 @@
</argument>
</arguments>
<options>
<option name="--help" shortcut="-h" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message.</description>
</option>
<option name="--quiet" shortcut="-q" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message.</description>
</option>
<option name="--verbose" shortcut="-v" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--verbose" shortcut="-v" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase verbosity of messages.</description>
</option>
<option name="--version" shortcut="-V" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this program version.</description>
</option>
<option name="--ansi" shortcut="-a" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--ansi" shortcut="-a" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output.</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_parameter="0" is_parameter_required="0" is_multiple="0">
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question.</description>
</option>
</options>

View File

@ -13,11 +13,11 @@
</argument>
</arguments>
<options>
<option name="--foo" shortcut="-f" accept_parameter="1" is_parameter_required="1" is_multiple="0">
<option name="--foo" shortcut="-f" accept_value="1" is_value_required="1" is_multiple="0">
<description>The foo option</description>
<defaults/>
</option>
<option name="--bar" shortcut="-b" accept_parameter="1" is_parameter_required="0" is_multiple="0">
<option name="--bar" shortcut="-b" accept_value="1" is_value_required="0" is_multiple="0">
<description>The foo option</description>
<defaults>
<default>bar</default>

View File

@ -35,53 +35,53 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$input = new TestInput(array('cli.php', '--foo'));
$input->bind(new InputDefinition(array(new InputOption('foo'))));
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses long options without parameter');
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses long options without a value');
$input = new TestInput(array('cli.php', '--foo=bar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required parameter (with a = separator)');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a = separator)');
$input = new TestInput(array('cli.php', '--foo', 'bar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required parameter (with a space separator)');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a space separator)');
try {
$input = new TestInput(array('cli.php', '--foo'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->fail('->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->fail('->parse() throws a \RuntimeException if no value is passed to an option when it is required');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
}
$input = new TestInput(array('cli.php', '-f'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'))));
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses short options without parameter');
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses short options without a value');
$input = new TestInput(array('cli.php', '-fbar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required parameter (with no separator)');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with no separator)');
$input = new TestInput(array('cli.php', '-f', 'bar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required parameter (with a space separator)');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with a space separator)');
$input = new TestInput(array('cli.php', '-f', '-b', 'foo'));
$input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL), new InputOption('bar', 'b'))));
$this->assertEquals(array('foo' => null, 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional parameter which is not present');
$input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b'))));
$this->assertEquals(array('foo' => null, 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional value which is not present');
try {
$input = new TestInput(array('cli.php', '-f'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$this->fail('->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->fail('->parse() throws a \RuntimeException if no value is passed to an option when it is required');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no parameter is passed to an option when it is required');
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
}
try {
$input = new TestInput(array('cli.php', '-ffoo'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_NONE))));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))));
$this->fail('->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
} catch (\Exception $e) {
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
@ -120,20 +120,20 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo' => true, 'bar' => true), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one');
$input = new TestInput(array('cli.php', '-fb', 'bar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::PARAMETER_REQUIRED))));
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has a required parameter');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_REQUIRED))));
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has a required value');
$input = new TestInput(array('cli.php', '-fb', 'bar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL))));
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional parameter');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value');
$input = new TestInput(array('cli.php', '-fbbar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL))));
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional parameter with no separator');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value with no separator');
$input = new TestInput(array('cli.php', '-fbbar'));
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL), new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL))));
$this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a parameter');
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
$this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a value');
}
public function testGetFirstArgument()

View File

@ -53,14 +53,14 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options');
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default'))));
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a default value');
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default'))));
$this->assertEquals(array('foo' => 'default'), $input->getOptions(), '->parse() parses long options with a default value');
try {
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED))));
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
$this->fail('->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');

View File

@ -277,13 +277,13 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
public function testGetOptionDefaults()
{
$definition = new InputDefinition(array(
new InputOption('foo1', null, InputOption::PARAMETER_NONE),
new InputOption('foo2', null, InputOption::PARAMETER_REQUIRED),
new InputOption('foo3', null, InputOption::PARAMETER_REQUIRED, '', 'default'),
new InputOption('foo4', null, InputOption::PARAMETER_OPTIONAL),
new InputOption('foo5', null, InputOption::PARAMETER_OPTIONAL, '', 'default'),
new InputOption('foo6', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY),
new InputOption('foo7', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, '', array(1, 2)),
new InputOption('foo1', null, InputOption::VALUE_NONE),
new InputOption('foo2', null, InputOption::VALUE_REQUIRED),
new InputOption('foo3', null, InputOption::VALUE_REQUIRED, '', 'default'),
new InputOption('foo4', null, InputOption::VALUE_OPTIONAL),
new InputOption('foo5', null, InputOption::VALUE_OPTIONAL, '', 'default'),
new InputOption('foo6', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY),
new InputOption('foo7', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, '', array(1, 2)),
));
$defaults = array(
'foo1' => null,
@ -303,9 +303,9 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('[--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputOption('foo', 'f')));
$this->assertEquals('[-f|--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED)));
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)));
$this->assertEquals('[-f|--foo="..."]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL)));
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)));
$this->assertEquals('[-f|--foo[="..."]]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputArgument('foo')));
@ -323,8 +323,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$definition = new InputDefinition(array(
new InputArgument('foo', InputArgument::OPTIONAL, 'The bar argument'),
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The foo argument', array('bar')),
new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL, 'The foo option', 'bar'),
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The foo option', 'bar'),
));
$this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
}
@ -334,8 +334,8 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$definition = new InputDefinition(array(
new InputArgument('foo', InputArgument::OPTIONAL, 'The bar argument'),
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The foo argument', array('bar')),
new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::PARAMETER_OPTIONAL, 'The foo option', 'bar'),
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The foo option', 'bar'),
));
$this->assertXmlStringEqualsXmlFile(self::$fixtures.'/definition_asxml.txt', $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
}

View File

@ -23,11 +23,11 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $option->getName(), '__construct() removes the leading -- of the option name');
try {
$option = new InputOption('foo', 'f', InputOption::PARAMETER_IS_ARRAY);
$this->fail('->setDefault() throws an Exception if PARAMETER_IS_ARRAY option is used when an option does not accept a value');
$option = new InputOption('foo', 'f', InputOption::VALUE_IS_ARRAY);
$this->fail('->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if PARAMETER_IS_ARRAY option is used when an option does not accept a value');
$this->assertEquals('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.', $e->getMessage());
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
$this->assertEquals('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.', $e->getMessage());
}
// shortcut argument
@ -38,29 +38,29 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
// mode argument
$option = new InputOption('foo', 'f');
$this->assertFalse($option->acceptParameter(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$this->assertFalse($option->isParameterRequired(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$this->assertFalse($option->isParameterOptional(), '__construct() gives a "Option::PARAMETER_NONE" mode by default');
$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', null);
$this->assertFalse($option->acceptParameter(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$this->assertFalse($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$this->assertFalse($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$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');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
$this->assertFalse($option->acceptParameter(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$this->assertFalse($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$this->assertFalse($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_NONE" as its mode');
$option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
$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');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED);
$this->assertTrue($option->acceptParameter(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
$this->assertTrue($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
$this->assertFalse($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_REQUIRED" as its mode');
$option = new InputOption('foo', 'f', InputOption::VALUE_REQUIRED);
$this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
$this->assertTrue($option->isValueRequired(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
$this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL);
$this->assertTrue($option->acceptParameter(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
$this->assertFalse($option->isParameterRequired(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
$this->assertTrue($option->isParameterOptional(), '__construct() can take "Option::PARAMETER_OPTIONAL" as its mode');
$option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL);
$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');
try {
$option = new InputOption('foo', 'f', 'ANOTHER_ONE');
@ -73,9 +73,9 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
public function testIsArray()
{
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
$option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
$this->assertTrue($option->isArray(), '->isArray() returns true if the option can be an array');
$option = new InputOption('foo', null, InputOption::PARAMETER_NONE);
$option = new InputOption('foo', null, InputOption::VALUE_NONE);
$this->assertFalse($option->isArray(), '->isArray() returns false if the option can not be an array');
}
@ -87,49 +87,49 @@ class InputOptionTest extends \PHPUnit_Framework_TestCase
public function testGetDefault()
{
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL, '', 'default');
$option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', 'default');
$this->assertEquals('default', $option->getDefault(), '->getDefault() returns the default value');
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED, '', 'default');
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED, '', 'default');
$this->assertEquals('default', $option->getDefault(), '->getDefault() returns the default value');
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED);
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED);
$this->assertNull($option->getDefault(), '->getDefault() returns null if no default value is configured');
$option = new InputOption('foo', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
$option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
$this->assertEquals(array(), $option->getDefault(), '->getDefault() returns an empty array if option is an array');
$option = new InputOption('foo', null, InputOption::PARAMETER_NONE);
$this->assertFalse($option->getDefault(), '->getDefault() returns false if the option does not take a parameter');
$option = new InputOption('foo', null, InputOption::VALUE_NONE);
$this->assertFalse($option->getDefault(), '->getDefault() returns false if the option does not take a value');
}
public function testSetDefault()
{
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED, '', 'default');
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED, '', 'default');
$option->setDefault(null);
$this->assertNull($option->getDefault(), '->setDefault() can reset the default value by passing null');
$option->setDefault('another');
$this->assertEquals('another', $option->getDefault(), '->setDefault() changes the default value');
$option = new InputOption('foo', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY);
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY);
$option->setDefault(array(1, 2));
$this->assertEquals(array(1, 2), $option->getDefault(), '->setDefault() changes the default value');
$option = new InputOption('foo', 'f', InputOption::PARAMETER_NONE);
$option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
try {
$option->setDefault('default');
$this->fail('->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
$this->fail('->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value for a PARAMETER_NONE option');
$this->assertEquals('Cannot set a default value when using Option::PARAMETER_NONE mode.', $e->getMessage());
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
$this->assertEquals('Cannot set a default value when using Option::VALUE_NONE mode.', $e->getMessage());
}
$option = new InputOption('foo', 'f', InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY);
$option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
try {
$option->setDefault('default');
$this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
$this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a VALUE_IS_ARRAY option');
} catch (\Exception $e) {
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a PARAMETER_IS_ARRAY option');
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a VALUE_IS_ARRAY option');
$this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
}
}

View File

@ -32,7 +32,7 @@ class InputTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
$this->assertEquals(array('name' => 'bar'), $input->getOptions(), '->getOptions() returns all option values');
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::PARAMETER_OPTIONAL, '', 'default'))));
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
$this->assertEquals('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
$this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getOptions(), '->getOptions() returns all option values, even optional ones');