14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Bridge \Twig \Command \LintCommand ;
16
16
use Symfony \Component \Console \Application ;
17
+ use Symfony \Component \Console \Command \Command ;
17
18
use Symfony \Component \Console \Output \OutputInterface ;
19
+ use Symfony \Component \Console \Tester \CommandCompletionTester ;
18
20
use Symfony \Component \Console \Tester \CommandTester ;
19
21
use Twig \Environment ;
20
22
use Twig \Loader \FilesystemLoader ;
@@ -134,7 +136,27 @@ public function testLintAutodetectsGithubActionEnvironment()
134
136
}
135
137
}
136
138
139
+ /**
140
+ * @dataProvider provideCompletionSuggestions
141
+ */
142
+ public function testComplete (array $ input , array $ expectedSuggestions )
143
+ {
144
+ $ tester = new CommandCompletionTester ($ this ->createCommand ());
145
+
146
+ $ this ->assertSame ($ expectedSuggestions , $ tester ->complete ($ input ));
147
+ }
148
+
149
+ public function provideCompletionSuggestions ()
150
+ {
151
+ yield 'option ' => [['--format ' , '' ], ['txt ' , 'json ' , 'github ' ]];
152
+ }
153
+
137
154
private function createCommandTester (): CommandTester
155
+ {
156
+ return new CommandTester ($ this ->createCommand ());
157
+ }
158
+
159
+ private function createCommand (): Command
138
160
{
139
161
$ environment = new Environment (new FilesystemLoader (\dirname (__DIR__ ).'/Fixtures/templates/ ' ));
140
162
$ environment ->addFilter (new TwigFilter ('deprecated_filter ' , function ($ v ) {
@@ -145,9 +167,8 @@ private function createCommandTester(): CommandTester
145
167
146
168
$ application = new Application ();
147
169
$ application ->add ($ command );
148
- $ command = $ application ->find ('lint:twig ' );
149
170
150
- return new CommandTester ( $ command );
171
+ return $ application -> find ( ' lint:twig ' );
151
172
}
152
173
153
174
private function createFile ($ content ): string
0 commit comments