Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 747e298

Browse filesBrowse files
bug #45181 [Console] Fix PHP 8.1 deprecation in ChoiceQuestion (BrokenSourceCode)
This PR was submitted for the 6.0 branch but it was squashed and merged into the 4.4 branch instead. Discussion ---------- [Console] Fix PHP 8.1 deprecation in ChoiceQuestion | Q | A | ------------- | --- | Branch? | ~6.0~ 4.4 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #45179 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Commits ------- aa89814 [Console] Fix PHP 8.1 deprecation in ChoiceQuestion
2 parents 8ba3fa7 + aa89814 commit 747e298
Copy full SHA for 747e298

File tree

2 files changed

+19
-5
lines changed
Filter options

2 files changed

+19
-5
lines changed

‎src/Symfony/Component/Console/Question/ChoiceQuestion.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Question/ChoiceQuestion.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,18 @@ private function getDefaultValidator(): callable
131131
return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
132132
if ($multiselect) {
133133
// Check for a separated comma values
134-
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) {
134+
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', (string) $selected, $matches)) {
135135
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
136136
}
137137

138-
$selectedChoices = explode(',', $selected);
138+
$selectedChoices = explode(',', (string) $selected);
139139
} else {
140140
$selectedChoices = [$selected];
141141
}
142142

143143
if ($this->isTrimmable()) {
144144
foreach ($selectedChoices as $k => $v) {
145-
$selectedChoices[$k] = trim($v);
145+
$selectedChoices[$k] = trim((string) $v);
146146
}
147147
}
148148

‎src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ class ChoiceQuestionTest extends TestCase
1919
/**
2020
* @dataProvider selectUseCases
2121
*/
22-
public function testSelectUseCases($multiSelect, $answers, $expected, $message)
22+
public function testSelectUseCases($multiSelect, $answers, $expected, $message, $default = null)
2323
{
2424
$question = new ChoiceQuestion('A question', [
2525
'First response',
2626
'Second response',
2727
'Third response',
2828
'Fourth response',
29-
]);
29+
null,
30+
], $default);
3031

3132
$question->setMultiselect($multiSelect);
3233

@@ -59,6 +60,19 @@ public function selectUseCases()
5960
['First response', 'Second response'],
6061
'When passed multiple answers on MultiSelect, the defaultValidator must return these answers as an array',
6162
],
63+
[
64+
false,
65+
[null],
66+
null,
67+
'When used null as default single answer on singleSelect, the defaultValidator must return this answer as null',
68+
],
69+
[
70+
false,
71+
['First response'],
72+
'First response',
73+
'When used a string as default single answer on singleSelect, the defaultValidator must return this answer as a string',
74+
'First response',
75+
],
6276
];
6377
}
6478

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.