3 namespace Stecman\Component\Symfony\Console\BashCompletion\Tests;
5 require_once __DIR__ . '/Common/CompletionHandlerTestCase.php';
7 use Stecman\Component\Symfony\Console\BashCompletion\Completion;
8 use Stecman\Component\Symfony\Console\BashCompletion\Tests\Common\CompletionHandlerTestCase;
10 class CompletionTest extends CompletionHandlerTestCase
13 * @dataProvider getCompletionTestInput
15 public function testCompletionResults($completions, $commandlineResultMap)
17 if (!is_array($completions)) {
18 $completions = array($completions);
21 foreach ($commandlineResultMap as $commandLine => $result) {
22 $handler = $this->createHandler($commandLine);
23 $handler->addHandlers($completions);
24 $this->assertEquals($result, $this->getTerms($handler->runCompletion()));
28 public function getCompletionTestInput()
30 $options = array('smooth', 'latin', 'moody');
33 'command match' => array(
37 Completion::ALL_TYPES,
41 'app walk:north --target ' => array(),
42 'app wave ' => $options
46 'type restriction option' => array(
48 Completion::ALL_COMMANDS,
50 Completion::TYPE_OPTION,
54 'app walk:north --target ' => $options,
55 'app wave ' => array()
59 'type restriction argument' => array(
61 Completion::ALL_COMMANDS,
63 Completion::TYPE_ARGUMENT,
67 'app walk:north --target ' => array(),
68 'app wave ' => $options
72 'makeGlobalHandler static' => array(
73 Completion::makeGlobalHandler(
75 Completion::ALL_TYPES,
79 'app walk:north --target ' => $options,
80 'app wave ' => $options
84 'with anonymous function' => array(
88 Completion::TYPE_OPTION,
94 'app walk:north --target ' => array(),
95 'app wave ' => array(),
96 'app wave --style ' => array(1, 2,3, 4, 5)
100 'with callable array' => array(
102 Completion::ALL_COMMANDS,
104 Completion::ALL_TYPES,
105 array($this, 'instanceMethodForCallableCheck')
108 'app walk:north --target ' => array('hello', 'world'),
109 'app wave ' => array('hello', 'world')
113 'multiple handlers' => array(
116 Completion::ALL_COMMANDS,
118 Completion::TYPE_OPTION,
119 array('all:option:target')
122 Completion::ALL_COMMANDS,
124 Completion::ALL_TYPES,
125 array('all:all:target')
128 Completion::ALL_COMMANDS,
130 Completion::TYPE_OPTION,
131 array('all:option:style')
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'),
146 * Used in the test "with callable array"
149 public function instanceMethodForCallableCheck()
151 return array('hello', 'world');