Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / symfony / console / Symfony / Component / Console / Tests / Input / InputArgumentTest.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\InputArgument;
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         // mode argument
24         $argument = new InputArgument('foo');
25         $this->assertFalse($argument->isRequired(), '__construct() gives a "InputArgument::OPTIONAL" mode by default');
26
27         $argument = new InputArgument('foo', null);
28         $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
29
30         $argument = new InputArgument('foo', InputArgument::OPTIONAL);
31         $this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
32
33         $argument = new InputArgument('foo', InputArgument::REQUIRED);
34         $this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode');
35
36         try {
37             $argument = new InputArgument('foo', 'ANOTHER_ONE');
38             $this->fail('__construct() throws an Exception if the mode is not valid');
39         } catch (\Exception $e) {
40             $this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
41             $this->assertEquals('Argument mode "ANOTHER_ONE" is not valid.', $e->getMessage());
42         }
43         try {
44             $argument = new InputArgument('foo', -1);
45             $this->fail('__construct() throws an Exception if the mode is not valid');
46         } catch (\Exception $e) {
47             $this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
48             $this->assertEquals('Argument mode "-1" is not valid.', $e->getMessage());
49         }
50     }
51
52     public function testIsArray()
53     {
54         $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
55         $this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
56         $argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
57         $this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
58         $argument = new InputArgument('foo', InputArgument::OPTIONAL);
59         $this->assertFalse($argument->isArray(), '->isArray() returns false if the argument can not be an array');
60     }
61
62     public function testGetDescription()
63     {
64         $argument = new InputArgument('foo', null, 'Some description');
65         $this->assertEquals('Some description', $argument->getDescription(), '->getDescription() return the message description');
66     }
67
68     public function testGetDefault()
69     {
70         $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
71         $this->assertEquals('default', $argument->getDefault(), '->getDefault() return the default value');
72     }
73
74     public function testSetDefault()
75     {
76         $argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
77         $argument->setDefault(null);
78         $this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null');
79         $argument->setDefault('another');
80         $this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
81
82         $argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
83         $argument->setDefault(array(1, 2));
84         $this->assertEquals(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value');
85
86         try {
87             $argument = new InputArgument('foo', InputArgument::REQUIRED);
88             $argument->setDefault('default');
89             $this->fail('->setDefault() throws an Exception if you give a default value for a required argument');
90         } catch (\Exception $e) {
91             $this->assertInstanceOf('\Exception', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
92             $this->assertEquals('Cannot set a default value except for Parameter::OPTIONAL mode.', $e->getMessage());
93         }
94
95         try {
96             $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
97             $argument->setDefault('default');
98             $this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
99         } catch (\Exception $e) {
100             $this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
101             $this->assertEquals('A default value for an array argument must be an array.', $e->getMessage());
102         }
103     }
104 }