Skip to content

Commit c195108

Browse files
Merge branch '4.2'
* 4.2: [HttpFoundation] Check file exists before unlink [Console] Fixed #29835: ConfirmationQuestion with default true for answer '0' [Cache] PDO-based cache pool table autocreation does not work [Translation] Concatenated translation messages [Form] ensure compatibility with older PHPUnit mocks [Serializer] Docblock about throwing exceptions on serializer [Cache] fix used variable name [Debug][ErrorHandler] Preserve our error handler when a logger set another one [Form] Changed UrlType input type to text when default_protocol is not null [Bugfix] MemcachedSessionHandler::close() must close connection Always pass $key to NullAdapter->createCacheItem
2 parents d78ff92 + 1f0ad51 commit c195108

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

Question/ConfirmationQuestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private function getDefaultNormalizer()
5353
return $answer && $answerIsTrue;
5454
}
5555

56-
return !$answer || $answerIsTrue;
56+
return '' === $answer || $answerIsTrue;
5757
};
5858
}
5959
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Question;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Question\ConfirmationQuestion;
16+
17+
class ConfirmationQuestionTest extends TestCase
18+
{
19+
/**
20+
* @dataProvider normalizerUsecases
21+
*/
22+
public function testDefaultRegexUsecases($default, $answers, $expected, $message)
23+
{
24+
$sut = new ConfirmationQuestion('A question', $default);
25+
26+
foreach ($answers as $answer) {
27+
$normalizer = $sut->getNormalizer();
28+
$actual = $normalizer($answer);
29+
$this->assertEquals($expected, $actual, sprintf($message, $answer));
30+
}
31+
}
32+
33+
public function normalizerUsecases()
34+
{
35+
return [
36+
[
37+
true,
38+
['y', 'Y', 'yes', 'YES', 'yEs', ''],
39+
true,
40+
'When default is true, the normalizer must return true for "%s"',
41+
],
42+
[
43+
true,
44+
['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0'],
45+
false,
46+
'When default is true, the normalizer must return false for "%s"',
47+
],
48+
[
49+
false,
50+
['y', 'Y', 'yes', 'YES', 'yEs'],
51+
true,
52+
'When default is false, the normalizer must return true for "%s"',
53+
],
54+
[
55+
false,
56+
['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0', ''],
57+
false,
58+
'When default is false, the normalizer must return false for "%s"',
59+
],
60+
];
61+
}
62+
}

0 commit comments

Comments
 (0)