2010-01-04 14:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the symfony package.
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once __DIR__.'/../../../../bootstrap.php';
|
|
|
|
|
2010-01-09 11:57:15 +00:00
|
|
|
use Symfony\Components\Console\Input\InputArgument;
|
|
|
|
use Symfony\Components\Console\Exception;
|
2010-01-04 14:42:28 +00:00
|
|
|
|
|
|
|
$t = new LimeTest(16);
|
|
|
|
|
|
|
|
// __construct()
|
|
|
|
$t->diag('__construct()');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo');
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->getName(), 'foo', '__construct() takes a name as its first argument');
|
|
|
|
|
|
|
|
// mode argument
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo');
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->isRequired(), false, '__construct() gives a "Argument::OPTIONAL" mode by default');
|
|
|
|
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', null);
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->isRequired(), false, '__construct() can take "Argument::OPTIONAL" as its mode');
|
|
|
|
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->isRequired(), false, '__construct() can take "Argument::PARAMETER_OPTIONAL" as its mode');
|
|
|
|
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::REQUIRED);
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->isRequired(), true, '__construct() can take "Argument::PARAMETER_REQUIRED" as its mode');
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', 'ANOTHER_ONE');
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->fail('__construct() throws an Exception if the mode is not valid');
|
|
|
|
}
|
|
|
|
catch (\Exception $e)
|
|
|
|
{
|
|
|
|
$t->pass('__construct() throws an Exception if the mode is not valid');
|
|
|
|
}
|
|
|
|
|
|
|
|
// ->isArray()
|
|
|
|
$t->diag('->isArray()');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::IS_ARRAY);
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->ok($argument->isArray(), '->isArray() returns true if the argument can be an array');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->ok(!$argument->isArray(), '->isArray() returns false if the argument can not be an array');
|
|
|
|
|
|
|
|
// ->getDescription()
|
|
|
|
$t->diag('->getDescription()');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', null, 'Some description');
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->getDescription(), 'Some description', '->getDescription() return the message description');
|
|
|
|
|
|
|
|
// ->getDefault()
|
|
|
|
$t->diag('->getDefault()');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
|
2010-01-04 14:42:28 +00:00
|
|
|
$t->is($argument->getDefault(), 'default', '->getDefault() return the default value');
|
|
|
|
|
|
|
|
// ->setDefault()
|
|
|
|
$t->diag('->setDefault()');
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
|
2010-01-04 14:42:28 +00:00
|
|
|
$argument->setDefault(null);
|
|
|
|
$t->ok(is_null($argument->getDefault()), '->setDefault() can reset the default value by passing null');
|
|
|
|
$argument->setDefault('another');
|
|
|
|
$t->is($argument->getDefault(), 'another', '->setDefault() changes the default value');
|
|
|
|
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
|
2010-01-04 14:42:28 +00:00
|
|
|
$argument->setDefault(array(1, 2));
|
|
|
|
$t->is($argument->getDefault(), array(1, 2), '->setDefault() changes the default value');
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::REQUIRED);
|
2010-01-04 14:42:28 +00:00
|
|
|
$argument->setDefault('default');
|
|
|
|
$t->fail('->setDefault() throws an Exception if you give a default value for a required argument');
|
|
|
|
}
|
|
|
|
catch (\Exception $e)
|
|
|
|
{
|
|
|
|
$t->pass('->setDefault() throws an Exception if you give a default value for a required argument');
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-01-08 10:00:18 +00:00
|
|
|
$argument = new InputArgument('foo', InputArgument::IS_ARRAY);
|
2010-01-04 14:42:28 +00:00
|
|
|
$argument->setDefault('default');
|
|
|
|
$t->fail('->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
|
|
|
|
}
|
|
|
|
catch (\Exception $e)
|
|
|
|
{
|
|
|
|
$t->pass('->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
|
|
|
|
}
|