Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee2c59b

Browse files
Merge branch '5.4' into 6.0
* 5.4: Revert "bug #45813 [HttpClient] Move Content-Type after Content-Length (nicolas-grekas)" [FrameworkBundle] Fix exit codes in debug:translation command [Cache] Declaratively declare/hide DoctrineProvider to avoid breaking static analysis [HttpClient] Let curl handle Content-Length headers Improve testsuite [HttpClient] Move Content-Type after Content-Length [HttpClient] minor cs fix [Config] Fix using null values with config builders
2 parents 5e4151f + 2de0ebe commit ee2c59b

35 files changed

+317
-132
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json"
6666
6767
echo COLUMNS=120 >> $GITHUB_ENV
68-
echo PHPUNIT="$(pwd)/phpunit --exclude-group tty,benchmark,intl-data" >> $GITHUB_ENV
68+
echo PHPUNIT="$(pwd)/phpunit --exclude-group tty,benchmark,intl-data,integration" >> $GITHUB_ENV
6969
echo COMPOSER_UP='composer update --no-progress --ansi' >> $GITHUB_ENV
7070
7171
SYMFONY_VERSIONS=$(git ls-remote -q --heads | cut -f2 | grep -o '/[1-9][0-9]*\.[0-9].*' | sort -V)

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131131
$locale = $input->getArgument('locale');
132132
$domain = $input->getOption('domain');
133133

134-
$exitCode = 0;
134+
$exitCode = self::SUCCESS;
135135

136136
/** @var KernelInterface $kernel */
137137
$kernel = $this->getApplication()->getKernel();
@@ -217,16 +217,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
217217
if (!$currentCatalogue->defines($messageId, $domain)) {
218218
$states[] = self::MESSAGE_MISSING;
219219

220-
$exitCode = $exitCode | self::EXIT_CODE_MISSING;
220+
if (!$input->getOption('only-unused')) {
221+
$exitCode = $exitCode | self::EXIT_CODE_MISSING;
222+
}
221223
}
222224
} elseif ($currentCatalogue->defines($messageId, $domain)) {
223225
$states[] = self::MESSAGE_UNUSED;
224226

225-
$exitCode = $exitCode | self::EXIT_CODE_UNUSED;
227+
if (!$input->getOption('only-missing')) {
228+
$exitCode = $exitCode | self::EXIT_CODE_UNUSED;
229+
}
226230
}
227231

228-
if (!\in_array(self::MESSAGE_UNUSED, $states) && true === $input->getOption('only-unused')
229-
|| !\in_array(self::MESSAGE_MISSING, $states) && true === $input->getOption('only-missing')) {
232+
if (!\in_array(self::MESSAGE_UNUSED, $states) && $input->getOption('only-unused')
233+
|| !\in_array(self::MESSAGE_MISSING, $states) && $input->getOption('only-missing')
234+
) {
230235
continue;
231236
}
232237

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
1616
use Symfony\Bundle\FrameworkBundle\Console\Application;
1717
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ExtensionWithoutConfigTestBundle\ExtensionWithoutConfigTestBundle;
18+
use Symfony\Component\Console\Command\Command;
1819
use Symfony\Component\Console\Tester\CommandCompletionTester;
1920
use Symfony\Component\Console\Tester\CommandTester;
2021
use Symfony\Component\DependencyInjection\Container;
@@ -36,7 +37,7 @@ public function testDebugMissingMessages()
3637
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);
3738

3839
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
39-
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_MISSING, $res);
40+
$this->assertSame(TranslationDebugCommand::EXIT_CODE_MISSING, $res);
4041
}
4142

4243
public function testDebugUnusedMessages()
@@ -45,7 +46,7 @@ public function testDebugUnusedMessages()
4546
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);
4647

4748
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
48-
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_UNUSED, $res);
49+
$this->assertSame(TranslationDebugCommand::EXIT_CODE_UNUSED, $res);
4950
}
5051

5152
public function testDebugFallbackMessages()
@@ -54,7 +55,7 @@ public function testDebugFallbackMessages()
5455
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'foo']);
5556

5657
$this->assertMatchesRegularExpression('/fallback/', $tester->getDisplay());
57-
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_FALLBACK, $res);
58+
$this->assertSame(TranslationDebugCommand::EXIT_CODE_FALLBACK, $res);
5859
}
5960

6061
public function testNoDefinedMessages()
@@ -63,7 +64,7 @@ public function testNoDefinedMessages()
6364
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'test']);
6465

6566
$this->assertMatchesRegularExpression('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
66-
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_GENERAL_ERROR, $res);
67+
$this->assertSame(TranslationDebugCommand::EXIT_CODE_GENERAL_ERROR, $res);
6768
}
6869

6970
public function testDebugDefaultDirectory()
@@ -74,7 +75,7 @@ public function testDebugDefaultDirectory()
7475

7576
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
7677
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
77-
$this->assertEquals($expectedExitStatus, $res);
78+
$this->assertSame($expectedExitStatus, $res);
7879
}
7980

8081
public function testDebugDefaultRootDirectory()
@@ -92,7 +93,7 @@ public function testDebugDefaultRootDirectory()
9293

9394
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
9495
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
95-
$this->assertEquals($expectedExitStatus, $res);
96+
$this->assertSame($expectedExitStatus, $res);
9697
}
9798

9899
public function testDebugCustomDirectory()
@@ -112,7 +113,7 @@ public function testDebugCustomDirectory()
112113

113114
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
114115
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
115-
$this->assertEquals($expectedExitStatus, $res);
116+
$this->assertSame($expectedExitStatus, $res);
116117
}
117118

118119
public function testDebugInvalidDirectory()
@@ -128,6 +129,22 @@ public function testDebugInvalidDirectory()
128129
$tester->execute(['locale' => 'en', 'bundle' => 'dir']);
129130
}
130131

132+
public function testNoErrorWithOnlyMissingOptionAndNoResults()
133+
{
134+
$tester = $this->createCommandTester([], ['foo' => 'foo']);
135+
$res = $tester->execute(['locale' => 'en', '--only-missing' => true]);
136+
137+
$this->assertSame(Command::SUCCESS, $res);
138+
}
139+
140+
public function testNoErrorWithOnlyUnusedOptionAndNoResults()
141+
{
142+
$tester = $this->createCommandTester(['foo' => 'foo']);
143+
$res = $tester->execute(['locale' => 'en', '--only-unused' => true]);
144+
145+
$this->assertSame(Command::SUCCESS, $res);
146+
}
147+
131148
protected function setUp(): void
132149
{
133150
$this->fs = new Filesystem();

src/Symfony/Component/Config/Builder/ClassBuilder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function build(): string
9090
USE
9191
9292
/**
93-
* This class is automatically generated to help creating config.
93+
* This class is automatically generated to help in creating a config.
9494
*/
9595
class CLASS IMPLEMENTS
9696
{
@@ -121,14 +121,15 @@ public function addMethod(string $name, string $body, array $params = []): void
121121
$this->methods[] = new Method(strtr($body, ['NAME' => $this->camelCase($name)] + $params));
122122
}
123123

124-
public function addProperty(string $name, string $classType = null): Property
124+
public function addProperty(string $name, string $classType = null, string $defaultValue = null): Property
125125
{
126126
$property = new Property($name, '_' !== $name[0] ? $this->camelCase($name) : $name);
127127
if (null !== $classType) {
128128
$property->setType($classType);
129129
}
130130
$this->properties[] = $property;
131-
$property->setContent(sprintf('private $%s;', $property->getName()));
131+
$defaultValue = null !== $defaultValue ? sprintf(' = %s', $defaultValue) : '';
132+
$property->setContent(sprintf('private $%s%s;', $property->getName(), $defaultValue));
132133

133134
return $property;
134135
}

src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
*/
3232
class ConfigBuilderGenerator implements ConfigBuilderGeneratorInterface
3333
{
34+
/**
35+
* @var ClassBuilder[]
36+
*/
3437
private array $classes = [];
3538
private string $outputDir;
3639

@@ -89,6 +92,9 @@ private function writeClasses(): void
8992
foreach ($this->classes as $class) {
9093
$this->buildConstructor($class);
9194
$this->buildToArray($class);
95+
if ($class->getProperties()) {
96+
$class->addProperty('_usedProperties', null, '[]');
97+
}
9298
$this->buildSetExtraKey($class);
9399

94100
file_put_contents($this->getFullPath($class), $class->build());
@@ -135,6 +141,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
135141
public function NAME(array $value = []): CLASS
136142
{
137143
if (null === $this->PROPERTY) {
144+
$this->_usedProperties[\'PROPERTY\'] = true;
138145
$this->PROPERTY = new CLASS($value);
139146
} elseif ([] !== $value) {
140147
throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\');
@@ -161,6 +168,7 @@ private function handleVariableNode(VariableNode $node, ClassBuilder $class): vo
161168
*/
162169
public function NAME(mixed $valueDEFAULT): static
163170
{
171+
$this->_usedProperties[\'PROPERTY\'] = true;
164172
$this->PROPERTY = $value;
165173
166174
return $this;
@@ -188,6 +196,7 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild
188196
*/
189197
public function NAME(ParamConfigurator|array $value): static
190198
{
199+
$this->_usedProperties[\'PROPERTY\'] = true;
191200
$this->PROPERTY = $value;
192201
193202
return $this;
@@ -201,6 +210,7 @@ public function NAME(ParamConfigurator|array $value): static
201210
*/
202211
public function NAME(string $VAR, TYPE $VALUE): static
203212
{
213+
$this->_usedProperties[\'PROPERTY\'] = true;
204214
$this->PROPERTY[$VAR] = $VALUE;
205215
206216
return $this;
@@ -224,6 +234,8 @@ public function NAME(string $VAR, TYPE $VALUE): static
224234
$body = '
225235
public function NAME(array $value = []): CLASS
226236
{
237+
$this->_usedProperties[\'PROPERTY\'] = true;
238+
227239
return $this->PROPERTY[] = new CLASS($value);
228240
}';
229241
$class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn()]);
@@ -232,9 +244,11 @@ public function NAME(array $value = []): CLASS
232244
public function NAME(string $VAR, array $VALUE = []): CLASS
233245
{
234246
if (!isset($this->PROPERTY[$VAR])) {
235-
return $this->PROPERTY[$VAR] = new CLASS($value);
247+
$this->_usedProperties[\'PROPERTY\'] = true;
248+
249+
return $this->PROPERTY[$VAR] = new CLASS($VALUE);
236250
}
237-
if ([] === $value) {
251+
if ([] === $VALUE) {
238252
return $this->PROPERTY[$VAR];
239253
}
240254
@@ -259,6 +273,7 @@ private function handleScalarNode(ScalarNode $node, ClassBuilder $class): void
259273
*/
260274
public function NAME($value): static
261275
{
276+
$this->_usedProperties[\'PROPERTY\'] = true;
262277
$this->PROPERTY = $value;
263278
264279
return $this;
@@ -368,7 +383,7 @@ private function buildToArray(ClassBuilder $class): void
368383
}
369384

370385
$body .= strtr('
371-
if (null !== $this->PROPERTY) {
386+
if (isset($this->_usedProperties[\'PROPERTY\'])) {
372387
$output[\'ORG_NAME\'] = '.$code.';
373388
}', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName()]);
374389
}
@@ -398,7 +413,8 @@ private function buildConstructor(ClassBuilder $class): void
398413
}
399414

400415
$body .= strtr('
401-
if (isset($value[\'ORG_NAME\'])) {
416+
if (array_key_exists(\'ORG_NAME\', $value)) {
417+
$this->_usedProperties[\'PROPERTY\'] = true;
402418
$this->PROPERTY = '.$code.';
403419
unset($value[\'ORG_NAME\']);
404420
}
@@ -443,11 +459,7 @@ private function buildSetExtraKey(ClassBuilder $class): void
443459
*/
444460
public function NAME(string $key, mixed $value): static
445461
{
446-
if (null === $value) {
447-
unset($this->_extraKeys[$key]);
448-
} else {
449-
$this->_extraKeys[$key] = $value;
450-
}
462+
$this->_extraKeys[$key] = $value;
451463
452464
return $this;
453465
}');

src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99

1010
/**
11-
* This class is automatically generated to help creating config.
11+
* This class is automatically generated to help in creating a config.
1212
*/
1313
class ReceivingConfig
1414
{
1515
private $priority;
1616
private $color;
17+
private $_usedProperties = [];
1718

1819
/**
1920
* @default null
@@ -22,6 +23,7 @@ class ReceivingConfig
2223
*/
2324
public function priority($value): static
2425
{
26+
$this->_usedProperties['priority'] = true;
2527
$this->priority = $value;
2628

2729
return $this;
@@ -34,6 +36,7 @@ public function priority($value): static
3436
*/
3537
public function color($value): static
3638
{
39+
$this->_usedProperties['color'] = true;
3740
$this->color = $value;
3841

3942
return $this;
@@ -42,12 +45,14 @@ public function color($value): static
4245
public function __construct(array $value = [])
4346
{
4447

45-
if (isset($value['priority'])) {
48+
if (array_key_exists('priority', $value)) {
49+
$this->_usedProperties['priority'] = true;
4650
$this->priority = $value['priority'];
4751
unset($value['priority']);
4852
}
4953

50-
if (isset($value['color'])) {
54+
if (array_key_exists('color', $value)) {
55+
$this->_usedProperties['color'] = true;
5156
$this->color = $value['color'];
5257
unset($value['color']);
5358
}
@@ -60,10 +65,10 @@ public function __construct(array $value = [])
6065
public function toArray(): array
6166
{
6267
$output = [];
63-
if (null !== $this->priority) {
68+
if (isset($this->_usedProperties['priority'])) {
6469
$output['priority'] = $this->priority;
6570
}
66-
if (null !== $this->color) {
71+
if (isset($this->_usedProperties['color'])) {
6772
$output['color'] = $this->color;
6873
}
6974

src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99

1010
/**
11-
* This class is automatically generated to help creating config.
11+
* This class is automatically generated to help in creating a config.
1212
*/
1313
class RoutingConfig
1414
{
1515
private $senders;
16+
private $_usedProperties = [];
1617

1718
/**
1819
* @param ParamConfigurator|list<ParamConfigurator|mixed> $value
@@ -21,6 +22,7 @@ class RoutingConfig
2122
*/
2223
public function senders(ParamConfigurator|array $value): static
2324
{
25+
$this->_usedProperties['senders'] = true;
2426
$this->senders = $value;
2527

2628
return $this;
@@ -29,7 +31,8 @@ public function senders(ParamConfigurator|array $value): static
2931
public function __construct(array $value = [])
3032
{
3133

32-
if (isset($value['senders'])) {
34+
if (array_key_exists('senders', $value)) {
35+
$this->_usedProperties['senders'] = true;
3336
$this->senders = $value['senders'];
3437
unset($value['senders']);
3538
}
@@ -42,7 +45,7 @@ public function __construct(array $value = [])
4245
public function toArray(): array
4346
{
4447
$output = [];
45-
if (null !== $this->senders) {
48+
if (isset($this->_usedProperties['senders'])) {
4649
$output['senders'] = $this->senders;
4750
}
4851

0 commit comments

Comments
 (0)