This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Question;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Question\ChoiceQuestion;
class ChoiceQuestionTest extends TestCase
{
/**
* @dataProvider selectUseCases
*/
public function testSelectUseCases($multiSelect, $answers, $expected, $message)
{
$question = new ChoiceQuestion('A question', [
'First response',
'Second response',
'Third response',
'Fourth response',
]);
$question->setMultiselect($multiSelect);
foreach ($answers as $answer) {
$validator = $question->getValidator();
$actual = $validator($answer);
$this->assertEquals($actual, $expected, $message);
}
}
public function selectUseCases()
{
return [
[
false,
['First response', 'First response ', ' First response', ' First response '],
'First response',
'When passed single answer on singleSelect, the defaultValidator must return this answer as a string',
],
[
true,
['First response', 'First response ', ' First response', ' First response '],
['First response'],
'When passed single answer on MultiSelect, the defaultValidator must return this answer as an array',
],
[
true,
['First response,Second response', ' First response , Second response '],
['First response', 'Second response'],
'When passed multiple answers on MultiSelect, the defaultValidator must return these answers as an array',
],
];
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\Tests\Question;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class ConfirmationQuestionTest extends TestCase
{
/**
* @dataProvider normalizerUsecases
*/
public function testDefaultRegexUsecases($default, $answers, $expected, $message)
{
$sut = new ConfirmationQuestion('A question', $default);
foreach ($answers as $answer) {
$normalizer = $sut->getNormalizer();
$actual = $normalizer($answer);
$this->assertEquals($expected, $actual, sprintf($message, $answer));
}
}
public function normalizerUsecases()
{
return [
[
true,
['y', 'Y', 'yes', 'YES', 'yEs', ''],
true,
'When default is true, the normalizer must return true for "%s"',
],
[
true,
['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0'],
false,
'When default is true, the normalizer must return false for "%s"',
],
[
false,
['y', 'Y', 'yes', 'YES', 'yEs'],
true,
'When default is false, the normalizer must return true for "%s"',
],
[
false,
['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0', ''],
false,
'When default is false, the normalizer must return false for "%s"',
],
];
}
}