TYPO3  7.6
InputTest.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 
18 
19 class InputTest extends \PHPUnit_Framework_TestCase
20 {
21  public function testConstructor()
22  {
23  $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
24  $this->assertEquals('foo', $input->getArgument('name'), '->__construct() takes a InputDefinition as an argument');
25  }
26 
27  public function testOptions()
28  {
29  $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'))));
30  $this->assertEquals('foo', $input->getOption('name'), '->getOption() returns the value for the given option');
31 
32  $input->setOption('name', 'bar');
33  $this->assertEquals('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
34  $this->assertEquals(array('name' => 'bar'), $input->getOptions(), '->getOptions() returns all option values');
35 
36  $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
37  $this->assertEquals('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
38  $this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getOptions(), '->getOptions() returns all option values, even optional ones');
39  }
40 
45  public function testSetInvalidOption()
46  {
47  $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
48  $input->setOption('foo', 'bar');
49  }
50 
55  public function testGetInvalidOption()
56  {
57  $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
58  $input->getOption('foo');
59  }
60 
61  public function testArguments()
62  {
63  $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
64  $this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
65 
66  $input->setArgument('name', 'bar');
67  $this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
68  $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
69 
70  $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
71  $this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
72  $this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
73  }
74 
79  public function testSetInvalidArgument()
80  {
81  $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
82  $input->setArgument('foo', 'bar');
83  }
84 
89  public function testGetInvalidArgument()
90  {
91  $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
92  $input->getArgument('foo');
93  }
94 
100  {
101  $input = new ArrayInput(array());
102  $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
103  $input->validate();
104  }
105 
106  public function testValidate()
107  {
108  $input = new ArrayInput(array('name' => 'foo'));
109  $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
110 
111  $this->assertNull($input->validate());
112  }
113 
114  public function testSetGetInteractive()
115  {
116  $input = new ArrayInput(array());
117  $this->assertTrue($input->isInteractive(), '->isInteractive() returns whether the input should be interactive or not');
118  $input->setInteractive(false);
119  $this->assertFalse($input->isInteractive(), '->setInteractive() changes the interactive flag');
120  }
121 }