10000 Merge branch '5.4' into 6.0 · symfony/symfony@e97a6f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit e97a6f7

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 bbe67c8 + 5107582 commit e97a6f7

File tree

102 files changed

+2049
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2049
-203
lines changed

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Console\Attribute\AsCommand;
1515
use Symfony\Component\Console\CI\GithubActionReporter;
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\Exception\RuntimeException;
1921
use Symfony\Component\Console\Input\InputArgument;
@@ -274,4 +276,11 @@ private function getContext(string $template, int $line, int $context = 3)
274276

275277
return $result;
276278
}
279+
280+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
281+
{
282+
if ($input->mustSuggestOptionValuesFor('format')) {
283+
$suggestions->suggestValues(['txt', 'json', 'github']);
284+
}
285+
}
277286
}

src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Twig\Command\LintCommand;
1616
use Symfony\Component\Console\Application;
17+
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\Console\Tester\CommandCompletionTester;
1820
use Symfony\Component\Console\Tester\CommandTester;
1921
use Twig\Environment;
2022
use Twig\Loader\FilesystemLoader;
@@ -134,7 +136,27 @@ public function testLintAutodetectsGithubActionEnvironment()
134136
}
135137
}
136138

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+
137154
private function createCommandTester(): CommandTester
155+
{
156+
return new CommandTester($this->createCommand());
157+
}
158+
159+
private function createCommand(): Command
138160
{
139161
$environment = new Environment(new FilesystemLoader(\dirname(__DIR__).'/Fixtures/templates/'));
140162
$environment->addFilter(new TwigFilter('deprecated_filter', function ($v) {
@@ -145,9 +167,8 @@ private function createCommandTester(): CommandTester
145167

146168
$application = new Application();
147169
$application->add($command);
148-
$command = $application->find('lint:twig');
149170

150-
return new CommandTester($command);
171+
return $application->find('lint:twig');
151172
}
152173

153174
private function createFile($content): string

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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 <fabien@symfony.com>
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+
}

src/Symfony/Bundle/FrameworkBundle/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+
}

src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ public static function createConnection(array|string $servers, array $options =
192192
if ('HASH' === $name || 'SERIALIZER' === $name || 'DISTRIBUTION' === $name) {
193193
$value = \constant('Memcached::'.$name.'_'.strtoupper($value));
194194
}
195-
$opt = \constant('Memcached::OPT_'.$name);
196-
197195
unset($options[$name]);
198-
$options[$opt] = $value;
196+
197+
if (\defined('Memcached::OPT_'.$name)) {
198+
$options[\constant('Memcached::OPT_'.$name)] = $value;
199+
}
199200
}
200201
$client->setOptions($options);
201202

0 commit comments

Comments
 (0)
0