Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / symfony / console / Symfony / Component / Console / Tests / Input / InputTest.php
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
14 use Symfony\Component\Console\Input\ArrayInput;
15 use Symfony\Component\Console\Input\InputDefinition;
16 use Symfony\Component\Console\Input\InputArgument;
17 use Symfony\Component\Console\Input\InputOption;
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         try {
41             $input->setOption('foo', 'bar');
42             $this->fail('->setOption() throws a \InvalidArgumentException if the option does not exist');
43         } catch (\Exception $e) {
44             $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
45             $this->assertEquals('The "foo" option does not exist.', $e->getMessage());
46         }
47
48         try {
49             $input->getOption('foo');
50             $this->fail('->getOption() throws a \InvalidArgumentException if the option does not exist');
51         } catch (\Exception $e) {
52             $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
53             $this->assertEquals('The "foo" option does not exist.', $e->getMessage());
54         }
55     }
56
57     public function testArguments()
58     {
59         $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
60         $this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
61
62         $input->setArgument('name', 'bar');
63         $this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
64         $this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
65
66         $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
67         $this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
68         $this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
69
70         try {
71             $input->setArgument('foo', 'bar');
72             $this->fail('->setArgument() throws a \InvalidArgumentException if the argument does not exist');
73         } catch (\Exception $e) {
74             $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
75             $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
76         }
77
78         try {
79             $input->getArgument('foo');
80             $this->fail('->getArgument() throws a \InvalidArgumentException if the argument does not exist');
81         } catch (\Exception $e) {
82             $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
83             $this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
84         }
85     }
86
87     public function testValidate()
88     {
89         $input = new ArrayInput(array());
90         $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
91
92         try {
93             $input->validate();
94             $this->fail('->validate() throws a \RuntimeException if not enough arguments are given');
95         } catch (\Exception $e) {
96             $this->assertInstanceOf('\RuntimeException', $e, '->validate() throws a \RuntimeException if not enough arguments are given');
97             $this->assertEquals('Not enough arguments.', $e->getMessage());
98         }
99
100         $input = new ArrayInput(array('name' => 'foo'));
101         $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
102
103         try {
104             $input->validate();
105         } catch (\RuntimeException $e) {
106             $this->fail('->validate() does not throw a \RuntimeException if enough arguments are given');
107         }
108     }
109
110     public function testSetFetInteractive()
111     {
112         $input = new ArrayInput(array());
113         $this->assertTrue($input->isInteractive(), '->isInteractive() returns whether the input should be interactive or not');
114         $input->setInteractive(false);
115         $this->assertFalse($input->isInteractive(), '->setInteractive() changes the interactive flag');
116     }
117 }