Skip to content

Navigation Menu

Sign in
Appearance settings

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 aa89814

Browse filesBrowse files
Rezyannicolas-grekas
authored andcommitted
[Console] Fix PHP 8.1 deprecation in ChoiceQuestion
1 parent 8ba3fa7 commit aa89814
Copy full SHA for aa89814

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.