Skip to content

Commit 49938d5

Browse files
Merge branch '5.4' into 6.0
* 5.4: (46 commits) move username/password fix to non-deprecated Connection class cs fix [VarDumper] Fix dumping twig templates found in exceptions do not replace definition arguments that have not been configured fix Console tests on Windows [Validator] Add translations for CIDR constraint [Dotenv] Fix testLoadEnv() to start from a fresh context [Console] Add completion to server:dump command bug #42194 [RateLimiter] fix: sliding window policy to use microtime [Validator] Update validators.sr_Cyrl.xlf [Validator] Update validators.sr_Latn.xlf Add suggestions for the option 'format' of lints commands: twig, yaml and xliff [VarDumper] Add support for Fiber uzb translation Update validators.uz.xlf Fix logging of impersonator introduced in 5.3 [Console] Add show proxified command class in completion debug skip command completion tests with older Symfony Console versions [Uid] Allow use autocompletion [Console] Add completion to messenger:setup-transports command ...
2 parents bd9c271 + 3ce0d40 commit 49938d5

8 files changed

+208
-6
lines changed

Command/CachePoolClearCommand.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Psr\Cache\CacheItemPoolInterface;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Completion\CompletionInput;
18+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1719
use Symfony\Component\Console\Exception\InvalidArgumentException;
1820
use Symfony\Component\Console\Input\InputArgument;
1921
use Symfony\Component\Console\Input\InputInterface;
@@ -30,12 +32,14 @@
3032
final class CachePoolClearCommand extends Command
3133
{
3234
private $poolClearer;
35+
private $poolNames;
3336

34-
public function __construct(Psr6CacheClearer $poolClearer)
37+
public function __construct(Psr6CacheClearer $poolClearer, array $poolNames = null)
3538
{
3639
parent::__construct();
3740

3841
$this->poolClearer = $poolClearer;
42+
$this->poolNames = $poolNames;
3943
}
4044

4145
/**
@@ -112,4 +116,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
112116

113117
return 0;
114118
}
119+
120+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
121+
{
122+
if (\is_array($this->poolNames) && $input->mustSuggestArgumentValuesFor('pools')) {
123+
$suggestions->suggestValues($this->poolNames);
124+
}
125+
}
115126
}

Command/CachePoolDeleteCommand.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Console\Attribute\AsCommand;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1618
use Symfony\Component\Console\Input\InputArgument;
1719
use Symfony\Component\Console\Input\InputInterface;
1820
use Symfony\Component\Console\Output\OutputInterface;
@@ -28,12 +30,14 @@
2830
final class CachePoolDeleteCommand extends Command
2931
{
3032
private $poolClearer;
33+
private $poolNames;
3134

32-
public function __construct(Psr6CacheClearer $poolClearer)
35+
public function __construct(Psr6CacheClearer $poolClearer, array $poolNames = null)
3336
{
3437
parent::__construct();
3538

3639
$this->poolClearer = $poolClearer;
40+
$this->poolNames = $poolNames;
3741
}
3842

3943
/**
@@ -79,4 +83,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7983

8084
return 0;
8185
}
86+
87+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
88+
{
89+
if (\is_array($this->poolNames) && $input->mustSuggestArgumentValuesFor('pool')) {
90+
$suggestions->suggestValues($this->poolNames);
91+
}
92+
}
8293
}

Command/SecretsRemoveCommand.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Completion\CompletionInput;
18-
use Symfony\Component\Console\Completion\CompletionInterface;
1918
use Symfony\Component\Console\Completion\CompletionSuggestions;
2019
use Symfony\Component\Console\Input\InputArgument;
2120
use Symfony\Component\Console\Input\InputInterface;
@@ -31,7 +30,7 @@
3130
* @internal
3231
*/
3332
#[AsCommand(name: 'secrets:remove', description: 'Remove a secret from the vault')]
34-
final class SecretsRemoveCommand extends Command implements CompletionInterface
33+
final class SecretsRemoveCommand extends Command
3534
{
3635
private $vault;
3736
private $localVault;
@@ -88,8 +87,14 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
8887
return;
8988
}
9089

91-
$vault = $input->getOption('local') ? $this->localVault : $this->vault;
9290
$vaultKeys = array_keys($this->vault->list(false));
93-
$suggestions->suggestValues(array_intersect($vaultKeys, array_keys($vault->list(false))));
91+
if ($input->getOption('local')) {
92+
if (null === $this->localVault) {
93+
return;
94+
}
95+
$vaultKeys = array_intersect($vaultKeys, array_keys($this->localVault->list(false)));
96+
}
97+
98+
$suggestions->suggestValues($vaultKeys);
9499
}
95100
}

Command/SecretsSetCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Completion\CompletionInput;
18+
use Symfony\Component\Console\Completion\CompletionSuggestions;
1719
use Symfony\Component\Console\Input\InputArgument;
1820
use Symfony\Component\Console\Input\InputInterface;
1921
use Symfony\Component\Console\Input\InputOption;
@@ -135,4 +137,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
135137

136138
return 0;
137139
}
140+
141+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
142+
{
143+
if ($input->mustSuggestArgumentValuesFor('name')) {
144+
$suggestions->suggestValues(array_keys($this->vault->list(false)));
145+
}
146+
}
138147
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
13+
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use Psr\Cache\CacheItemPoolInterface;
16+
use Symfony\Bundle\FrameworkBundle\Command\CachePoolClearCommand;
17+
use Symfony\Bundle\FrameworkBundle\Console\Application;
18+
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
19+
use Symfony\Component\Console\Tester\CommandCompletionTester;
20+
use Symfony\Component\DependencyInjection\ContainerInterface;
21+
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
22+
use Symfony\Component\HttpKernel\KernelInterface;
23+
24+
class CachePoolClearCommandTest extends TestCase
25+
{
26+
private $cachePool;
27+
28+
protected function setUp(): void
29+
{
30+
$this->cachePool = $this->createMock(CacheItemPoolInterface::class);
31+
}
32+
33+
/**
34+
* @dataProvider provideCompletionSuggestions
35+
*/
36+
public function testComplete(array $input, array $expectedSuggestions)
37+
{
38+
$application = new Application($this->getKernel());
39+
$application->add(new CachePoolClearCommand(new Psr6CacheClearer(['foo' => $this->cachePool]), ['foo']));
40+
$tester = new CommandCompletionTester($application->get('cache:pool:clear'));
41+
42+
$suggestions = $tester->complete($input);
43+
44+
$this->assertSame($expectedSuggestions, $suggestions);
45+
}
46+
47+
public function provideCompletionSuggestions()
48+
{
49+
yield 'pool_name' => [
50+
['f'],
51+
['foo'],
52+
];
53+
}
54+
55+
/**
56+
* @return MockObject&KernelInterface
57+
*/
58+
private function getKernel(): KernelInterface
59+
{
60+
$container = $this->createMock(ContainerInterface::class);
61+
62+
$kernel = $this->createMock(KernelInterface::class);
63+
$kernel
64+
->expects($this->any())
65+
->method('getContainer')
66+
->willReturn($container);
67+
68+
$kernel
69+
->expects($this->once())
70+
->method('getBundles')
71+
->willReturn([]);
72+
73+
return $kernel;
74+
}
75+
}

Tests/Command/CachePoolDeleteCommandTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Bundle\FrameworkBundle\Command\CachePoolDeleteCommand;
1717
use Symfony\Bundle\FrameworkBundle\Console\Application;
1818
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
19+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1920
use Symfony\Component\Console\Tester\CommandTester;
2021
use Symfony\Component\DependencyInjection\ContainerInterface;
2122
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
@@ -83,6 +84,28 @@ public function testCommandDeleteFailed()
8384
$tester->execute(['pool' => 'foo', 'key' => 'bar']);
8485
}
8586

87+
/**
88+
* @dataProvider provideCompletionSuggestions
89+
*/
90+
public function testComplete(array $input, array $expectedSuggestions)
91+
{
92+
$application = new Application($this->getKernel());
93+
$application->add(new CachePoolDeleteCommand(new Psr6CacheClearer(['foo' => $this->cachePool]), ['foo']));
94+
$tester = new CommandCompletionTester($application->get('cache:pool:delete'));
95+
96+
$suggestions = $tester->complete($input);
97+
98+
$this->assertSame($expectedSuggestions, $suggestions);
99+
}
100+
101+
public function provideCompletionSuggestions()
102+
{
103+
yield 'pool_name' => [
104+
['f'],
105+
['foo'],
106+
];
107+
}
108+
86109
/**
87110
* @return MockObject&KernelInterface
88111
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Bundle\FrameworkBundle\Command\SecretsRemoveCommand;
7+
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
8+
use Symfony\Component\Console\Tester\CommandCompletionTester;
9+
10+
class SecretsRemoveCommandTest extends TestCase
11+
{
12+
/**
13+
* @dataProvider provideCompletionSuggestions
14+
*/
15+
public function testComplete(bool $withLocalVault, array $input, array $expectedSuggestions)
16+
{
17+
$vault = $this->createMock(AbstractVault::class);
18+
$vault->method('list')->willReturn(['SECRET' => null, 'OTHER_SECRET' => null]);
19+
if ($withLocalVault) {
20+
$localVault = $this->createMock(AbstractVault::class);
21+
$localVault->method('list')->willReturn(['SECRET' => null]);
22+
} else {
23+
$localVault = null;
24+
}
25+
$command = new SecretsRemoveCommand($vault, $localVault);
26+
$tester = new CommandCompletionTester($command);
27+
$suggestions = $tester->complete($input);
28+
$this->assertSame($expectedSuggestions, $suggestions);
29+
}
30+
31+
public function provideCompletionSuggestions()
32+
{
33+
yield 'name' => [true, [''], ['SECRET', 'OTHER_SECRET']];
34+
yield '--local name (with local vault)' => [true, ['--local', ''], ['SECRET']];
35+
yield '--local name (without local vault)' => [false, ['--local', ''], []];
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Bundle\FrameworkBundle\Command\SecretsSetCommand;
7+
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
8+
use Symfony\Component\Console\Tester\CommandCompletionTester;
9+
10+
class SecretsSetCommandTest extends TestCase
11+
{
12+
/**
13+
* @dataProvider provideCompletionSuggestions
14+
*/
15+
public function testComplete(array $input, array $expectedSuggestions)
16+
{
17+
$vault = $this->createMock(AbstractVault::class);
18+
$vault->method('list')->willReturn(['SECRET' => null, 'OTHER_SECRET' => null]);
19+
$localVault = $this->createMock(AbstractVault::class);
20+
$command = new SecretsSetCommand($vault, $localVault);
21+
$tester = new CommandCompletionTester($command);
22+
$suggestions = $tester->complete($input);
23+
$this->assertSame($expectedSuggestions, $suggestions);
24+
}
25+
26+
public function provideCompletionSuggestions()
27+
{
28+
yield 'name' => [[''], ['SECRET', 'OTHER_SECRET']];
29+
yield '--local name (with local vault)' => [['--local', ''], ['SECRET', 'OTHER_SECRET']];
30+
}
31+
}

0 commit comments

Comments
 (0)