Skip to content

Commit 643f8d1

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: [TwigBridge] Remove `VersionAwareTest` from `AbstractLayoutTestCase` [DependencyInjection] Add coverage for error cases of `LazyClosure` and `AutowireLocator` [TwigBridge] Fixed a parameterized choice label translation Fix extracting of message from ->trans() method with named params Add missing Albanian translations for Security and Validator components [HttpClient] Add `crypto_method` to scoped client options suppress proc_open errors [DependencyInjection] Fix `XmlFileLoader` not respecting when env for services
2 parents e89da97 + a7e13a0 commit 643f8d1

File tree

21 files changed

+253
-89
lines changed

21 files changed

+253
-89
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\FormError;
2020
use Symfony\Component\Form\FormRenderer;
2121
use Symfony\Component\Form\FormView;
22+
use Symfony\Contracts\Translation\TranslatableInterface;
2223
use Symfony\Contracts\Translation\TranslatorInterface;
2324
use Twig\Extension\AbstractExtension;
2425
use Twig\TwigFilter;
@@ -147,23 +148,26 @@ public function getFieldChoices(FormView $view): iterable
147148
private function createFieldChoicesList(iterable $choices, string|false|null $translationDomain): iterable
148149
{
149150
foreach ($choices as $choice) {
150-
$translatableLabel = $this->createFieldTranslation($choice->label, [], $translationDomain);
151-
152151
if ($choice instanceof ChoiceGroupView) {
152+
$translatableLabel = $this->createFieldTranslation($choice->label, [], $translationDomain);
153153
yield $translatableLabel => $this->createFieldChoicesList($choice, $translationDomain);
154154

155155
continue;
156156
}
157157

158158
/* @var ChoiceView $choice */
159+
$translatableLabel = $this->createFieldTranslation($choice->label, $choice->labelTranslationParameters, $translationDomain);
159160
yield $translatableLabel => $choice->value;
160161
}
161162
}
162163

163-
private function createFieldTranslation(?string $value, array $parameters, string|false|null $domain): ?string
164+
private function createFieldTranslation(TranslatableInterface|string|null $value, array $parameters, string|false|null $domain): ?string
164165
{
165166
if (!$this->translator || !$value || false === $domain) {
166-
return $value;
167+
return null !== $value ? (string) $value : null;
168+
}
169+
if ($value instanceof TranslatableInterface) {
170+
return $value->trans($this->translator);
167171
}
168172

169173
return $this->translator->trans($value, $parameters, $domain);

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTestCase.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,8 +2869,6 @@ public function testColor()
28692869

28702870
public function testWeekSingleText()
28712871
{
2872-
$this->requiresFeatureSet(404);
2873-
28742872
$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
28752873
'input' => 'string',
28762874
'widget' => 'single_text',
@@ -2889,8 +2887,6 @@ public function testWeekSingleText()
28892887

28902888
public function testWeekSingleTextNoHtml5()
28912889
{
2892-
$this->requiresFeatureSet(404);
2893-
28942890
$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
28952891
'input' => 'string',
28962892
'widget' => 'single_text',
@@ -2910,8 +2906,6 @@ public function testWeekSingleTextNoHtml5()
29102906

29112907
public function testWeekChoices()
29122908
{
2913-
$this->requiresFeatureSet(404);
2914-
29152909
$data = ['year' => (int) date('Y'), 'week' => 1];
29162910

29172911
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', $data, [
@@ -2938,8 +2932,6 @@ public function testWeekChoices()
29382932

29392933
public function testWeekText()
29402934
{
2941-
$this->requiresFeatureSet(404);
2942-
29432935
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '2000-W01', [
29442936
'input' => 'string',
29452937
'widget' => 'text',

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap5LayoutTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,8 +1842,6 @@ public function testTimezoneWithPlaceholder()
18421842

18431843
public function testWeekChoices()
18441844
{
1845-
$this->requiresFeatureSet(404);
1846-
18471845
$data = ['year' => (int) date('Y'), 'week' => 1];
18481846

18491847
$form = $this->factory->createNamed('name', WeekType::class, $data, [

src/Symfony/Bridge/Twig/Tests/Extension/AbstractLayoutTestCase.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
1919
use Symfony\Component\Form\FormError;
2020
use Symfony\Component\Form\FormView;
21-
use Symfony\Component\Form\Tests\VersionAwareTest;
2221
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
2322
use Symfony\Component\Translation\TranslatableMessage;
2423
use Symfony\Contracts\Translation\TranslatableInterface;
2524
use Symfony\Contracts\Translation\TranslatorInterface;
2625

2726
abstract class AbstractLayoutTestCase extends FormLayoutTestCase
2827
{
29-
use VersionAwareTest;
30-
3128
protected MockObject&CsrfTokenManagerInterface $csrfTokenManager;
3229
protected array $testableFeatures = [];
3330

@@ -672,8 +669,6 @@ public function testSingleExpandedChoiceAttributesWithMainAttributes()
672669

673670
public function testSingleChoiceWithPreferred()
674671
{
675-
$this->requiresFeatureSet(404);
676-
677672
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
678673
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
679674
'preferred_choices' => ['&b'],
@@ -698,8 +693,6 @@ public function testSingleChoiceWithPreferred()
698693

699694
public function testSingleChoiceWithPreferredAndNoSeparator()
700695
{
701-
$this->requiresFeatureSet(404);
702-
703696
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
704697
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
705698
'preferred_choices' => ['&b'],
@@ -723,8 +716,6 @@ public function testSingleChoiceWithPreferredAndNoSeparator()
723716

724717
public function testSingleChoiceWithPreferredAndBlankSeparator()
725718
{
726-
$this->requiresFeatureSet(404);
727-
728719
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
729720
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
730721
'preferred_choices' => ['&b'],
@@ -749,8 +740,6 @@ public function testSingleChoiceWithPreferredAndBlankSeparator()
749740

750741
public function testChoiceWithOnlyPreferred()
751742
{
752-
$this->requiresFeatureSet(404);
753-
754743
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
755744
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
756745
'preferred_choices' => ['&a', '&b'],
@@ -1814,8 +1803,6 @@ public function testNumber()
18141803

18151804
public function testRenderNumberWithHtml5NumberType()
18161805
{
1817-
$this->requiresFeatureSet(403);
1818-
18191806
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
18201807
'html5' => true,
18211808
]);
@@ -1832,8 +1819,6 @@ public function testRenderNumberWithHtml5NumberType()
18321819

18331820
public function testRenderNumberWithHtml5NumberTypeAndStepAttribute()
18341821
{
1835-
$this->requiresFeatureSet(403);
1836-
18371822
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\NumberType', 1234.56, [
18381823
'html5' => true,
18391824
'attr' => ['step' => '0.1'],
@@ -1908,8 +1893,6 @@ public function testPercent()
19081893

19091894
public function testPercentNoSymbol()
19101895
{
1911-
$this->requiresFeatureSet(403);
1912-
19131896
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false, 'rounding_mode' => \NumberFormatter::ROUND_CEILING]);
19141897
$this->assertWidgetMatchesXpath($form->createView(), [],
19151898
'/input
@@ -1923,8 +1906,6 @@ public function testPercentNoSymbol()
19231906

19241907
public function testPercentCustomSymbol()
19251908
{
1926-
$this->requiresFeatureSet(403);
1927-
19281909
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '', 'rounding_mode' => \NumberFormatter::ROUND_CEILING]);
19291910
$this->assertWidgetMatchesXpath($form->createView(), [],
19301911
'/input
@@ -2602,8 +2583,6 @@ public function testColor()
26022583

26032584
public function testLabelWithTranslationParameters()
26042585
{
2605-
$this->requiresFeatureSet(403);
2606-
26072586
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
26082587
$html = $this->renderLabel($form->createView(), 'Address is %address%', [
26092588
'label_translation_parameters' => [
@@ -2621,8 +2600,6 @@ public function testLabelWithTranslationParameters()
26212600

26222601
public function testHelpWithTranslationParameters()
26232602
{
2624-
$this->requiresFeatureSet(403);
2625-
26262603
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
26272604
'help' => 'for company %company%',
26282605
'help_translation_parameters' => [
@@ -2693,8 +2670,6 @@ public function trans(TranslatorInterface $translator, ?string $locale = null):
26932670

26942671
public function testAttributesWithTranslationParameters()
26952672
{
2696-
$this->requiresFeatureSet(403);
2697-
26982673
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
26992674
'attr' => [
27002675
'title' => 'Message to %company%',
@@ -2716,8 +2691,6 @@ public function testAttributesWithTranslationParameters()
27162691

27172692
public function testButtonWithTranslationParameters()
27182693
{
2719-
$this->requiresFeatureSet(403);
2720-
27212694
$form = $this->factory->createNamedBuilder('myform')
27222695
->add('mybutton', 'Symfony\Component\Form\Extension\Core\Type\ButtonType', [
27232696
'label' => 'Submit to %company%',
@@ -2741,8 +2714,6 @@ public function testButtonWithTranslationParameters()
27412714
*/
27422715
public function testSubmitFormNoValidate(bool $validate)
27432716
{
2744-
$this->requiresFeatureSet(404);
2745-
27462717
$form = $this->factory->create(SubmitType::class, null, [
27472718
'validate' => $validate,
27482719
]);
@@ -2772,8 +2743,6 @@ public static function submitFormNoValidateProvider()
27722743

27732744
public function testWeekSingleText()
27742745
{
2775-
$this->requiresFeatureSet(404);
2776-
27772746
$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
27782747
'input' => 'string',
27792748
'widget' => 'single_text',
@@ -2791,8 +2760,6 @@ public function testWeekSingleText()
27912760

27922761
public function testWeekSingleTextNoHtml5()
27932762
{
2794-
$this->requiresFeatureSet(404);
2795-
27962763
$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01', [
27972764
'input' => 'string',
27982765
'widget' => 'single_text',
@@ -2811,8 +2778,6 @@ public function testWeekSingleTextNoHtml5()
28112778

28122779
public function testWeekChoices()
28132780
{
2814-
$this->requiresFeatureSet(404);
2815-
28162781
$data = ['year' => (int) date('Y'), 'week' => 1];
28172782

28182783
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', $data, [
@@ -2837,8 +2802,6 @@ public function testWeekChoices()
28372802

28382803
public function testWeekText()
28392804
{
2840-
$this->requiresFeatureSet(404);
2841-
28422805
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '2000-W01', [
28432806
'input' => 'string',
28442807
'widget' => 'text',

src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\FormError;
2020
use Symfony\Component\Form\FormView;
2121
use Symfony\Component\Form\Test\FormIntegrationTestCase;
22+
use Symfony\Component\Translation\TranslatableMessage;
2223

2324
class FormExtensionFieldHelpersTest extends FormIntegrationTestCase
2425
{
@@ -81,6 +82,28 @@ protected function setUp(): void
8182
'expanded' => true,
8283
'label' => false,
8384
])
85+
->add('parametrized_choice_label', ChoiceType::class, [
86+
'choices' => [
87+
(object) ['value' => 'yes', 'label' => 'parametrized.%yes%'],
88+
(object) ['value' => 'no', 'label' => 'parametrized.%no%'],
89+
],
90+
'choice_value' => 'value',
91+
'choice_label' => 'label',
92+
'choice_translation_domain' => 'forms',
93+
'choice_translation_parameters' => [
94+
['%yes%' => 'YES'],
95+
['%no%' => 'NO'],
96+
],
97+
])
98+
->add('translatable_choice_label', ChoiceType::class, [
99+
'choices' => [
100+
'yes',
101+
'no',
102+
],
103+
'choice_label' => static function (string $choice) {
104+
return new TranslatableMessage('parametrized.%value%', ['%value%' => $choice], 'forms');
105+
},
106+
])
84107
->getForm()
85108
;
86109

@@ -290,4 +313,40 @@ public function testFieldTranslatedChoicesMultiple()
290313
$this->assertSame('salt', $choicesArray[1]['value']);
291314
$this->assertSame('[trans]base.salt[/trans]', $choicesArray[1]['label']);
292315
}
316+
317+
public function testChoiceParametrizedLabel()
318+
{
319+
$choices = $this->translatorExtension->getFieldChoices($this->view->children['parametrized_choice_label']);
320+
321+
$choicesArray = [];
322+
foreach ($choices as $label => $value) {
323+
$choicesArray[] = ['label' => $label, 'value' => $value];
324+
}
325+
326+
$this->assertCount(2, $choicesArray);
327+
328+
$this->assertSame('yes', $choicesArray[0]['value']);
329+
$this->assertSame('[trans]parametrized.YES[/trans]', $choicesArray[0]['label']);
330+
331+
$this->assertSame('no', $choicesArray[1]['value']);
332+
$this->assertSame('[trans]parametrized.NO[/trans]', $choicesArray[1]['label']);
333+
}
334+
335+
public function testChoiceTranslatableLabel()
336+
{
337+
$choices = $this->translatorExtension->getFieldChoices($this->view->children['translatable_choice_label']);
338+
339+
$choicesArray = [];
340+
foreach ($choices as $label => $value) {
341+
$choicesArray[] = ['label' => $label, 'value' => $value];
342+
}
343+
344+
$this->assertCount(2, $choicesArray);
345+
346+
$this->assertSame('yes', $choicesArray[0]['value']);
347+
$this->assertSame('[trans]parametrized.yes[/trans]', $choicesArray[0]['label']);
348+
349+
$this->assertSame('no', $choicesArray[1]['value']);
350+
$this->assertSame('[trans]parametrized.no[/trans]', $choicesArray[1]['label']);
351+
}
293352
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,9 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
20062006
->variableNode('md5')->end()
20072007
->end()
20082008
->end()
2009+
->scalarNode('crypto_method')
2010+
->info('The minimum version of TLS to accept; must be one of STREAM_CRYPTO_METHOD_TLSv*_CLIENT constants.')
2011+
->end()
20092012
->arrayNode('extra')
20102013
->info('Extra options for specific HTTP client')
20112014
->normalizeKeys(false)

src/Symfony/Component/Console/Terminal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private static function readFromProcess(string|array $command): ?string
209209

210210
$cp = \function_exists('sapi_windows_cp_set') ? sapi_windows_cp_get() : 0;
211211

212-
if (!$process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true])) {
212+
if (!$process = @proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true])) {
213213
return null;
214214
}
215215

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function parseImports(\DOMDocument $xml, string $file, ?\DOMNode $root =
118118
$xpath = new \DOMXPath($xml);
119119
$xpath->registerNamespace('container', self::NS);
120120

121-
if (false === $imports = $xpath->query('.//container:imports/container:import', $root)) {
121+
if (false === $imports = $xpath->query('./container:imports/container:import', $root)) {
122122
return;
123123
}
124124

@@ -134,14 +134,14 @@ private function parseDefinitions(\DOMDocument $xml, string $file, Definition $d
134134
$xpath = new \DOMXPath($xml);
135135
$xpath->registerNamespace('container', self::NS);
136136

137-
if (false === $services = $xpath->query('.//container:services/container:service|.//container:services/container:prototype|.//container:services/container:stack', $root)) {
137+
if (false === $services = $xpath->query('./container:services/container:service|./container:services/container:prototype|./container:services/container:stack', $root)) {
138138
return;
139139
}
140140
$this->setCurrentDir(\dirname($file));
141141

142142
$this->instanceof = [];
143143
$this->isLoadingInstanceof = true;
144-
$instanceof = $xpath->query('.//container:services/container:instanceof', $root);
144+
$instanceof = $xpath->query('./container:services/container:instanceof', $root);
145145
foreach ($instanceof as $service) {
146146
$this->setDefinition((string) $service->getAttribute('id'), $this->parseDefinition($service, $file, new Definition()));
147147
}
@@ -192,7 +192,7 @@ private function getServiceDefaults(\DOMDocument $xml, string $file, ?\DOMNode $
192192
$xpath = new \DOMXPath($xml);
193193
$xpath->registerNamespace('container', self::NS);
194194

195-
if (null === $defaultsNode = $xpath->query('.//container:services/container:defaults', $root)->item(0)) {
195+
if (null === $defaultsNode = $xpath->query('./container:services/container:defaults', $root)->item(0)) {
196196
return new Definition();
197197
}
198198

0 commit comments

Comments
 (0)