Merge branch '4.4'
* 4.4: relax some assertions to make tests forward compatible skip updated ChoiceType tests on older versions fix typo make tests forward compatible with DI 4.4 fix test fix expected exception message regex Fix multiSelect ChoiceQuestion when answers have spaces
This commit is contained in:
commit
9edb23d7e2
@ -222,7 +222,7 @@ install:
|
||||
composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master
|
||||
|
||||
- |
|
||||
# Legacy tests are skipped when deps=high and when the current branch version has not the same major version number than the next one
|
||||
# Legacy tests are skipped when deps=high and when the current branch version has not the same major version number as the next one
|
||||
[[ $deps = high && ${SYMFONY_VERSION%.*} != $(git show $(git ls-remote --heads | grep -FA1 /$SYMFONY_VERSION | tail -n 1):composer.json | grep '^ *"dev-master". *"[1-9]' | grep -o '[0-9]*' | head -n 1) ]] && LEGACY=,legacy
|
||||
|
||||
export COMPOSER_ROOT_VERSION=$SYMFONY_VERSION.x-dev
|
||||
|
@ -31,7 +31,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
protected static $supportedFeatureSetVersion = 403;
|
||||
protected static $supportedFeatureSetVersion = 404;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
protected static $supportedFeatureSetVersion = 403;
|
||||
protected static $supportedFeatureSetVersion = 404;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
|
@ -129,17 +129,15 @@ class ChoiceQuestion extends Question
|
||||
$isAssoc = $this->isAssoc($choices);
|
||||
|
||||
return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
|
||||
// Collapse all spaces.
|
||||
$selectedChoices = str_replace(' ', '', $selected);
|
||||
|
||||
if ($multiselect) {
|
||||
// Check for a separated comma values
|
||||
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
|
||||
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) {
|
||||
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
|
||||
}
|
||||
$selectedChoices = explode(',', $selectedChoices);
|
||||
|
||||
$selectedChoices = array_map('trim', explode(',', $selected));
|
||||
} else {
|
||||
$selectedChoices = [$selected];
|
||||
$selectedChoices = [trim($selected)];
|
||||
}
|
||||
|
||||
$multiselectChoices = [];
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@ -726,6 +726,8 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
|
||||
|
||||
public function testSingleChoiceWithPreferred()
|
||||
{
|
||||
$this->requiresFeatureSet(404);
|
||||
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
|
||||
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
|
||||
'preferred_choices' => ['&b'],
|
||||
@ -750,6 +752,8 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
|
||||
|
||||
public function testSingleChoiceWithPreferredAndNoSeparator()
|
||||
{
|
||||
$this->requiresFeatureSet(404);
|
||||
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
|
||||
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
|
||||
'preferred_choices' => ['&b'],
|
||||
@ -773,6 +777,8 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
|
||||
|
||||
public function testSingleChoiceWithPreferredAndBlankSeparator()
|
||||
{
|
||||
$this->requiresFeatureSet(404);
|
||||
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
|
||||
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
|
||||
'preferred_choices' => ['&b'],
|
||||
@ -797,6 +803,8 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
|
||||
|
||||
public function testChoiceWithOnlyPreferred()
|
||||
{
|
||||
$this->requiresFeatureSet(404);
|
||||
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
|
||||
'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
|
||||
'preferred_choices' => ['&a', '&b'],
|
||||
|
@ -37,7 +37,7 @@ class TraceableMessageBusTest extends TestCase
|
||||
unset($actualTracedMessage['callTime']); // don't check, too variable
|
||||
$this->assertEquals([
|
||||
'message' => $message,
|
||||
'stamps' => [[$stamp]],
|
||||
'stamps' => [$stamp],
|
||||
'caller' => [
|
||||
'name' => 'TraceableMessageBusTest.php',
|
||||
'file' => __FILE__,
|
||||
|
@ -189,7 +189,7 @@ abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAcces
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
|
||||
* @expectedExceptionMessageRegExp /Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_Car[^"]*": The property "axes" in class "Mock_PropertyAccessorCollectionTest_Car[^"]*" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\Traversable, "string" given./
|
||||
* @expectedExceptionMessageRegExp /Could not determine access type for property "axes" in class "Symfony\\Component\\PropertyAccess\\Tests\\PropertyAccessorCollectionTest_Car[^"]*": The property "axes" in class "Symfony\\Component\\PropertyAccess\\Tests\\PropertyAccessorCollectionTest_Car[^"]*" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\Traversable, "string" given./
|
||||
*/
|
||||
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
|
||||
{
|
||||
|
Reference in New Issue
Block a user