|
9 | 9 | * file that was distributed with this source code.
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -namespace Symfony\Bundle\FrameworkBundle\Tests\Command; |
| 12 | +namespace Symfony\Component\Translation\Tests\Command; |
13 | 13 |
|
14 | 14 | use Symfony\Component\Console\Application;
|
| 15 | +use Symfony\Component\Console\Tester\CommandCompletionTester; |
15 | 16 | use Symfony\Component\Console\Tester\CommandTester;
|
16 | 17 | use Symfony\Component\Translation\Command\TranslationPushCommand;
|
17 | 18 | use Symfony\Component\Translation\Loader\ArrayLoader;
|
18 | 19 | use Symfony\Component\Translation\Loader\XliffFileLoader;
|
19 | 20 | use Symfony\Component\Translation\Provider\ProviderInterface;
|
20 | 21 | use Symfony\Component\Translation\Reader\TranslationReader;
|
21 |
| -use Symfony\Component\Translation\Tests\Command\TranslationProviderTestCase; |
22 | 22 | use Symfony\Component\Translation\TranslatorBag;
|
23 | 23 |
|
24 | 24 | /**
|
@@ -249,20 +249,56 @@ public function testPushForceAndDeleteMissingMessages()
|
249 | 249 | $this->assertStringContainsString('[OK] All local translations has been sent to "null" (for "en, fr" locale(s), and "messages" domain(s)).', trim($tester->getDisplay()));
|
250 | 250 | }
|
251 | 251 |
|
| 252 | + /** |
| 253 | + * @dataProvider provideCompletionSuggestions |
| 254 | + */ |
| 255 | + public function testComplete(array $input, array $expectedSuggestions) |
| 256 | + { |
| 257 | + $application = new Application(); |
| 258 | + $application->add($this->createCommand($this->createMock(ProviderInterface::class), ['en', 'fr', 'it'], ['messages', 'validators'], ['loco', 'crowdin', 'lokalise'])); |
| 259 | + |
| 260 | + $tester = new CommandCompletionTester($application->get('translation:push')); |
| 261 | + $suggestions = $tester->complete($input); |
| 262 | + $this->assertSame($expectedSuggestions, $suggestions); |
| 263 | + } |
| 264 | + |
| 265 | + public function provideCompletionSuggestions(): \Generator |
| 266 | + { |
| 267 | + yield 'provider' => [ |
| 268 | + [''], |
| 269 | + ['loco', 'crowdin', 'lokalise'], |
| 270 | + ]; |
| 271 | + |
| 272 | + yield '--domains' => [ |
| 273 | + ['loco', '--domains'], |
| 274 | + ['messages', 'validators'], |
| 275 | + ]; |
| 276 | + |
| 277 | + yield '--locales' => [ |
| 278 | + ['loco', '--locales'], |
| 279 | + ['en', 'fr', 'it'], |
| 280 | + ]; |
| 281 | + } |
| 282 | + |
252 | 283 | private function createCommandTester(ProviderInterface $provider, array $locales = ['en'], array $domains = ['messages']): CommandTester
|
| 284 | + { |
| 285 | + $command = $this->createCommand($provider, $locales, $domains); |
| 286 | + $application = new Application(); |
| 287 | + $application->add($command); |
| 288 | + |
| 289 | + return new CommandTester($application->find('translation:push')); |
| 290 | + } |
| 291 | + |
| 292 | + private function createCommand(ProviderInterface $provider, array $locales = ['en'], array $domains = ['messages'], array $providerNames = ['loco']): TranslationPushCommand |
253 | 293 | {
|
254 | 294 | $reader = new TranslationReader();
|
255 | 295 | $reader->addLoader('xlf', new XliffFileLoader());
|
256 | 296 |
|
257 |
| - $command = new TranslationPushCommand( |
258 |
| - $this->getProviderCollection($provider, $locales, $domains), |
| 297 | + return new TranslationPushCommand( |
| 298 | + $this->getProviderCollection($provider, $providerNames, $locales, $domains), |
259 | 299 | $reader,
|
260 | 300 | [$this->translationAppDir.'/translations'],
|
261 | 301 | $locales
|
262 | 302 | );
|
263 |
| - $application = new Application(); |
264 |
| - $application->add($command); |
265 |
| - |
266 |
| - return new CommandTester($application->find('translation:push')); |
267 | 303 | }
|
268 | 304 | }
|
0 commit comments