TYPO3  7.6
InputArgumentTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Tests\Input;
13 
15 
16 class InputArgumentTest extends \PHPUnit_Framework_TestCase
17 {
18  public function testConstructor()
19  {
20  $argument = new InputArgument('foo');
21  $this->assertEquals('foo', $argument->getName(), '__construct() takes a name as its first argument');
22  }
23 
24  public function testModes()
25  {
26  $argument = new InputArgument('foo');
27  $this->assertFalse($argument->isRequired(), '__construct() gives a "InputArgument::OPTIONAL" mode by default');
28 
29  $argument = new InputArgument('foo', null);
30  $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
31 
32  $argument = new InputArgument('foo', InputArgument::OPTIONAL);
33  $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
34 
35  $argument = new InputArgument('foo', InputArgument::REQUIRED);
36  $this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode');
37  }
38 
42  public function testInvalidModes($mode)
43  {
44  $this->setExpectedException('InvalidArgumentException', sprintf('Argument mode "%s" is not valid.', $mode));
45 
46  new InputArgument('foo', $mode);
47  }
48 
49  public function provideInvalidModes()
50  {
51  return array(
52  array('ANOTHER_ONE'),
53  array(-1),
54  );
55  }
56 
57  public function testIsArray()
58  {
59  $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
60  $this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
62  $this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
63  $argument = new InputArgument('foo', InputArgument::OPTIONAL);
64  $this->assertFalse($argument->isArray(), '->isArray() returns false if the argument can not be an array');
65  }
66 
67  public function testGetDescription()
68  {
69  $argument = new InputArgument('foo', null, 'Some description');
70  $this->assertEquals('Some description', $argument->getDescription(), '->getDescription() return the message description');
71  }
72 
73  public function testGetDefault()
74  {
75  $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
76  $this->assertEquals('default', $argument->getDefault(), '->getDefault() return the default value');
77  }
78 
79  public function testSetDefault()
80  {
81  $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
82  $argument->setDefault(null);
83  $this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null');
84  $argument->setDefault('another');
85  $this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
86 
88  $argument->setDefault(array(1, 2));
89  $this->assertEquals(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value');
90  }
91 
97  {
98  $argument = new InputArgument('foo', InputArgument::REQUIRED);
99  $argument->setDefault('default');
100  }
101 
107  {
108  $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
109  $argument->setDefault('default');
110  }
111 }