Skip to content

Commit 2f90325

Browse files
Merge branch '4.4' into 5.3
* 4.4: [Cache] workaround PHP crash [Console] Fix PHP 8.1 deprecation in ChoiceQuestion Making the parser stateless
2 parents a890459 + 32ba2ac commit 2f90325

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Question/ChoiceQuestion.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ private function getDefaultValidator(): callable
125125
return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
126126
if ($multiselect) {
127127
// Check for a separated comma values
128-
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) {
128+
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', (string) $selected, $matches)) {
129129
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
130130
}
131131

132-
$selectedChoices = explode(',', $selected);
132+
$selectedChoices = explode(',', (string) $selected);
133133
} else {
134134
$selectedChoices = [$selected];
135135
}
136136

137137
if ($this->isTrimmable()) {
138138
foreach ($selectedChoices as $k => $v) {
139-
$selectedChoices[$k] = trim($v);
139+
$selectedChoices[$k] = trim((string) $v);
140140
}
141141
}
142142

Tests/Question/ChoiceQuestionTest.php

Lines 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
false,
6478
[0],

0 commit comments

Comments
 (0)