summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Tests/Input/ArrayInputTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/console/Tests/Input/ArrayInputTest.php')
-rw-r--r--vendor/symfony/console/Tests/Input/ArrayInputTest.php42
1 files changed, 39 insertions, 3 deletions
diff --git a/vendor/symfony/console/Tests/Input/ArrayInputTest.php b/vendor/symfony/console/Tests/Input/ArrayInputTest.php
index cc89083c..3e858435 100644
--- a/vendor/symfony/console/Tests/Input/ArrayInputTest.php
+++ b/vendor/symfony/console/Tests/Input/ArrayInputTest.php
@@ -11,12 +11,13 @@
namespace Symfony\Component\Console\Tests\Input;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
-class ArrayInputTest extends \PHPUnit_Framework_TestCase
+class ArrayInputTest extends TestCase
{
public function testGetFirstArgument()
{
@@ -36,15 +37,24 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
$input = new ArrayInput(array('--foo'));
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
+
+ $input = new ArrayInput(array('--foo', '--', '--bar'));
+ $this->assertTrue($input->hasParameterOption('--bar'), '->hasParameterOption() returns true if an option is present in the passed parameters');
+ $this->assertFalse($input->hasParameterOption('--bar', true), '->hasParameterOption() returns false if an option is present in the passed parameters after an end of options signal');
}
public function testGetParameterOption()
{
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
+ $this->assertFalse($input->getParameterOption('--bar'), '->getParameterOption() returns the default if an option is not present in the passed parameters');
$input = new ArrayInput(array('Fabien', '--foo' => 'bar'));
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
+
+ $input = new ArrayInput(array('--foo', '--', '--bar' => 'woop'));
+ $this->assertEquals('woop', $input->getParameterOption('--bar'), '->getParameterOption() returns the correct value if an option is present in the passed parameters');
+ $this->assertFalse($input->getParameterOption('--bar', false, true), '->getParameterOption() returns false if an option is present in the passed parameters after an end of options signal');
}
public function testParseArguments()
@@ -80,9 +90,15 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
'->parse() parses long options with a default value',
),
array(
- array('--foo' => null),
+ array(),
array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default')),
array('foo' => 'default'),
+ '->parse() uses the default value for long options with value optional which are not passed',
+ ),
+ array(
+ array('--foo' => null),
+ array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default')),
+ array('foo' => null),
'->parse() parses long options with a default value',
),
array(
@@ -91,6 +107,18 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
array('foo' => 'bar'),
'->parse() parses short options',
),
+ array(
+ array('--' => null, '-f' => 'bar'),
+ array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default')),
+ array('foo' => 'default'),
+ '->parse() does not parse opts after an end of options signal',
+ ),
+ array(
+ array('--' => null),
+ array(),
+ array(),
+ '->parse() does not choke on end of options signal',
+ ),
);
}
@@ -99,7 +127,12 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
*/
public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage)
{
- $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException('InvalidArgumentException');
+ $this->expectExceptionMessage($expectedExceptionMessage);
+ } else {
+ $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
+ }
new ArrayInput($parameters, $definition);
}
@@ -134,5 +167,8 @@ class ArrayInputTest extends \PHPUnit_Framework_TestCase
{
$input = new ArrayInput(array('-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"));
$this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
+
+ $input = new ArrayInput(array('-b' => array('bval_1', 'bval_2'), '--f' => array('fval_1', 'fval_2')));
+ $this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
}
}