40901a2c77aeef7011abc1fa1df93bcff0f8fed1
[yaffs-website] / vendor / stecman / symfony-console-completion / tests / Stecman / Component / Symfony / Console / BashCompletion / CompletionTest.php
1 <?php
2
3 namespace Stecman\Component\Symfony\Console\BashCompletion\Tests;
4
5 require_once __DIR__ . '/Common/CompletionHandlerTestCase.php';
6
7 use Stecman\Component\Symfony\Console\BashCompletion\Completion;
8 use Stecman\Component\Symfony\Console\BashCompletion\Tests\Common\CompletionHandlerTestCase;
9
10 class CompletionTest extends CompletionHandlerTestCase
11 {
12     /**
13      * @dataProvider getCompletionTestInput
14      */
15     public function testCompletionResults($completions, $commandlineResultMap)
16     {
17         if (!is_array($completions)) {
18             $completions = array($completions);
19         }
20
21         foreach ($commandlineResultMap as $commandLine => $result) {
22             $handler = $this->createHandler($commandLine);
23             $handler->addHandlers($completions);
24             $this->assertEquals($result, $this->getTerms($handler->runCompletion()));
25         }
26     }
27
28     public function getCompletionTestInput()
29     {
30         $options = array('smooth', 'latin', 'moody');
31
32         return array(
33             'command match' => array(
34                 new Completion(
35                     'wave',
36                     'target',
37                     Completion::ALL_TYPES,
38                     $options
39                 ),
40                 array(
41                     'app walk:north --target ' => array(),
42                     'app wave ' => $options
43                 )
44             ),
45
46             'type restriction option' => array(
47                 new Completion(
48                     Completion::ALL_COMMANDS,
49                     'target',
50                     Completion::TYPE_OPTION,
51                     $options
52                 ),
53                 array(
54                     'app walk:north --target ' => $options,
55                     'app wave ' => array()
56                 )
57             ),
58
59             'type restriction argument' => array(
60                 new Completion(
61                     Completion::ALL_COMMANDS,
62                     'target',
63                     Completion::TYPE_ARGUMENT,
64                     $options
65                 ),
66                 array(
67                     'app walk:north --target ' => array(),
68                     'app wave ' => $options
69                 )
70             ),
71
72             'makeGlobalHandler static' => array(
73                 Completion::makeGlobalHandler(
74                     'target',
75                     Completion::ALL_TYPES,
76                     $options
77                 ),
78                 array(
79                     'app walk:north --target ' => $options,
80                     'app wave ' => $options
81                 )
82             ),
83
84             'with anonymous function' => array(
85                 new Completion(
86                     'wave',
87                     'style',
88                     Completion::TYPE_OPTION,
89                     function() {
90                         return range(1, 5);
91                     }
92                 ),
93                 array(
94                     'app walk:north --target ' => array(),
95                     'app wave ' => array(),
96                     'app wave --style ' => array(1, 2,3, 4, 5)
97                 )
98             ),
99
100             'with callable array' => array(
101                 new Completion(
102                     Completion::ALL_COMMANDS,
103                     'target',
104                     Completion::ALL_TYPES,
105                     array($this, 'instanceMethodForCallableCheck')
106                 ),
107                 array(
108                     'app walk:north --target ' => array('hello', 'world'),
109                     'app wave ' => array('hello', 'world')
110                 )
111             ),
112
113             'multiple handlers' => array(
114                 array(
115                     new Completion(
116                         Completion::ALL_COMMANDS,
117                         'target',
118                         Completion::TYPE_OPTION,
119                         array('all:option:target')
120                     ),
121                     new Completion(
122                         Completion::ALL_COMMANDS,
123                         'target',
124                         Completion::ALL_TYPES,
125                         array('all:all:target')
126                     ),
127                     new Completion(
128                         Completion::ALL_COMMANDS,
129                         'style',
130                         Completion::TYPE_OPTION,
131                         array('all:option:style')
132                     ),
133                 ),
134                 array(
135                     'app walk:north ' => array(),
136                     'app walk:north -t ' => array('all:option:target'),
137                     'app wave ' => array('all:all:target'),
138                     'app wave bruce -s ' => array('all:option:style'),
139                     'app walk:north --style ' => array('all:option:style'),
140                 )
141             )
142         );
143     }
144
145     /**
146      * Used in the test "with callable array"
147      * @return array
148      */
149     public function instanceMethodForCallableCheck()
150     {
151         return array('hello', 'world');
152     }
153 }