forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleParserTest.php
More file actions
147 lines (115 loc) · 6.62 KB
/
ConsoleParserTest.php
File metadata and controls
147 lines (115 loc) · 6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace Illuminate\Tests\Console;
use Illuminate\Console\Parser;
use PHPUnit\Framework\TestCase;
class ConsoleParserTest extends TestCase
{
public function testBasicParameterParsing()
{
$results = Parser::parse('command:name');
$this->assertEquals('command:name', $results[0]);
$results = Parser::parse('command:name {argument} {--option}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('argument', $results[1][0]->getName());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertFalse($results[2][0]->acceptValue());
$results = Parser::parse('command:name {argument*} {--option=}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('argument', $results[1][0]->getName());
$this->assertTrue($results[1][0]->isArray());
$this->assertTrue($results[1][0]->isRequired());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertTrue($results[2][0]->acceptValue());
$results = Parser::parse('command:name {argument?*} {--option=*}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('argument', $results[1][0]->getName());
$this->assertTrue($results[1][0]->isArray());
$this->assertFalse($results[1][0]->isRequired());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
$results = Parser::parse('command:name {argument?* : The argument description.} {--option=* : The option description.}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('argument', $results[1][0]->getName());
$this->assertEquals('The argument description.', $results[1][0]->getDescription());
$this->assertTrue($results[1][0]->isArray());
$this->assertFalse($results[1][0]->isRequired());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertEquals('The option description.', $results[2][0]->getDescription());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
$results = Parser::parse('command:name
{argument?* : The argument description.}
{--option=* : The option description.}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('argument', $results[1][0]->getName());
$this->assertEquals('The argument description.', $results[1][0]->getDescription());
$this->assertTrue($results[1][0]->isArray());
$this->assertFalse($results[1][0]->isRequired());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertEquals('The option description.', $results[2][0]->getDescription());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
}
public function testShortcutNameParsing()
{
$results = Parser::parse('command:name {--o|option}');
$this->assertEquals('o', $results[2][0]->getShortcut());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertFalse($results[2][0]->acceptValue());
$results = Parser::parse('command:name {--o|option=}');
$this->assertEquals('o', $results[2][0]->getShortcut());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertTrue($results[2][0]->acceptValue());
$results = Parser::parse('command:name {--o|option=*}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('o', $results[2][0]->getShortcut());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
$results = Parser::parse('command:name {--o|option=* : The option description.}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('o', $results[2][0]->getShortcut());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertEquals('The option description.', $results[2][0]->getDescription());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
$results = Parser::parse('command:name
{--o|option=* : The option description.}');
$this->assertEquals('command:name', $results[0]);
$this->assertEquals('o', $results[2][0]->getShortcut());
$this->assertEquals('option', $results[2][0]->getName());
$this->assertEquals('The option description.', $results[2][0]->getDescription());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
}
public function testDefaultValueParsing()
{
$results = Parser::parse('command:name {argument=defaultArgumentValue} {--option=defaultOptionValue}');
$this->assertFalse($results[1][0]->isRequired());
$this->assertEquals('defaultArgumentValue', $results[1][0]->getDefault());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertEquals('defaultOptionValue', $results[2][0]->getDefault());
$results = Parser::parse('command:name {argument=*defaultArgumentValue1,defaultArgumentValue2} {--option=*defaultOptionValue1,defaultOptionValue2}');
$this->assertTrue($results[1][0]->isArray());
$this->assertFalse($results[1][0]->isRequired());
$this->assertEquals(['defaultArgumentValue1', 'defaultArgumentValue2'], $results[1][0]->getDefault());
$this->assertTrue($results[2][0]->acceptValue());
$this->assertTrue($results[2][0]->isArray());
$this->assertEquals(['defaultOptionValue1', 'defaultOptionValue2'], $results[2][0]->getDefault());
}
public function testArgumentDefaultValue()
{
$results = Parser::parse('command:name {argument= : The argument description.}');
$this->assertNull($results[1][0]->getDefault());
$results = Parser::parse('command:name {argument=default : The argument description.}');
$this->assertSame('default', $results[1][0]->getDefault());
}
public function testOptionDefaultValue()
{
$results = Parser::parse('command:name {--option= : The option description.}');
$this->assertNull($results[2][0]->getDefault());
$results = Parser::parse('command:name {--option=default : The option description.}');
$this->assertSame('default', $results[2][0]->getDefault());
}
}