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
107 lines (84 loc) · 4.81 KB
/
ConsoleParserTest.php
File metadata and controls
107 lines (84 loc) · 4.81 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
<?php
use Illuminate\Console\Parser;
class ConsoleParserTest extends PHPUnit_Framework_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());
}
}