comparison vendor/pear/console_commandline/tests/console_commandline_addoption.phpt @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
1 --TEST--
2 Test for Console_CommandLine::addOption() method.
3 --FILE--
4 <?php
5
6 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
7
8 $parser = new Console_CommandLine();
9 $parser->addOption('opt1', array(
10 'short_name' => '-a'
11 ));
12 $parser->addOption('opt2', array(
13 'short_name' => '-b',
14 'long_name' => '--foo',
15 'description' => 'description of opt2',
16 'action' => 'StoreInt',
17 'help_name' => 'bar',
18 'choices' => array(1, 2, 3),
19 'add_list_option' => true,
20 'default' => 2
21 ));
22 $opt3 = new Console_CommandLine_Option('opt3', array(
23 'long_name' => '--bar',
24 'description' => 'description of opt3',
25 ));
26 $parser->addOption($opt3);
27
28 var_dump($parser->options);
29
30 ?>
31 --EXPECTF--
32 array(4) {
33 ["opt1"]=>
34 object(Console_CommandLine_Option)#%d (14) {
35 ["short_name"]=>
36 string(2) "-a"
37 ["long_name"]=>
38 NULL
39 ["action"]=>
40 string(11) "StoreString"
41 ["choices"]=>
42 array(0) {
43 }
44 ["callback"]=>
45 NULL
46 ["action_params"]=>
47 array(0) {
48 }
49 ["argument_optional"]=>
50 bool(false)
51 ["add_list_option"]=>
52 bool(false)
53 [%s]=>
54 NULL
55 ["name"]=>
56 string(4) "opt1"
57 ["help_name"]=>
58 string(4) "opt1"
59 ["description"]=>
60 NULL
61 ["default"]=>
62 NULL
63 ["messages"]=>
64 array(0) {
65 }
66 }
67 ["opt2"]=>
68 object(Console_CommandLine_Option)#%d (14) {
69 ["short_name"]=>
70 string(2) "-b"
71 ["long_name"]=>
72 string(5) "--foo"
73 ["action"]=>
74 string(8) "StoreInt"
75 ["choices"]=>
76 array(3) {
77 [0]=>
78 int(1)
79 [1]=>
80 int(2)
81 [2]=>
82 int(3)
83 }
84 ["callback"]=>
85 NULL
86 ["action_params"]=>
87 array(0) {
88 }
89 ["argument_optional"]=>
90 bool(false)
91 ["add_list_option"]=>
92 bool(true)
93 [%s]=>
94 NULL
95 ["name"]=>
96 string(4) "opt2"
97 ["help_name"]=>
98 string(3) "bar"
99 ["description"]=>
100 string(19) "description of opt2"
101 ["default"]=>
102 int(2)
103 ["messages"]=>
104 array(0) {
105 }
106 }
107 ["list_opt2"]=>
108 object(Console_CommandLine_Option)#%d (14) {
109 ["short_name"]=>
110 NULL
111 ["long_name"]=>
112 string(11) "--list-opt2"
113 ["action"]=>
114 string(4) "List"
115 ["choices"]=>
116 array(0) {
117 }
118 ["callback"]=>
119 NULL
120 ["action_params"]=>
121 array(1) {
122 ["list"]=>
123 array(3) {
124 [0]=>
125 int(1)
126 [1]=>
127 int(2)
128 [2]=>
129 int(3)
130 }
131 }
132 ["argument_optional"]=>
133 bool(false)
134 ["add_list_option"]=>
135 bool(false)
136 [%s]=>
137 NULL
138 ["name"]=>
139 string(9) "list_opt2"
140 ["help_name"]=>
141 string(9) "list_opt2"
142 ["description"]=>
143 string(35) "lists valid choices for option opt2"
144 ["default"]=>
145 NULL
146 ["messages"]=>
147 array(0) {
148 }
149 }
150 ["opt3"]=>
151 object(Console_CommandLine_Option)#%d (14) {
152 ["short_name"]=>
153 NULL
154 ["long_name"]=>
155 string(5) "--bar"
156 ["action"]=>
157 string(11) "StoreString"
158 ["choices"]=>
159 array(0) {
160 }
161 ["callback"]=>
162 NULL
163 ["action_params"]=>
164 array(0) {
165 }
166 ["argument_optional"]=>
167 bool(false)
168 ["add_list_option"]=>
169 bool(false)
170 [%s]=>
171 NULL
172 ["name"]=>
173 string(4) "opt3"
174 ["help_name"]=>
175 string(4) "opt3"
176 ["description"]=>
177 string(19) "description of opt3"
178 ["default"]=>
179 NULL
180 ["messages"]=>
181 array(0) {
182 }
183 }
184 }