diff --git a/.travis.yml b/.travis.yml index f2b7ed7df8..b5e7eb9ecd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 807f58c384..67ab832c59 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -31,7 +31,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest */ private $renderer; - protected static $supportedFeatureSetVersion = 403; + protected static $supportedFeatureSetVersion = 404; protected function setUp() { diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php index ecafc8b8de..c858d5bfa7 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php @@ -30,7 +30,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest */ private $renderer; - protected static $supportedFeatureSetVersion = 403; + protected static $supportedFeatureSetVersion = 404; protected function setUp() { diff --git a/src/Symfony/Component/Console/Question/ChoiceQuestion.php b/src/Symfony/Component/Console/Question/ChoiceQuestion.php index 612e406a8e..44b70abf11 100644 --- a/src/Symfony/Component/Console/Question/ChoiceQuestion.php +++ b/src/Symfony/Component/Console/Question/ChoiceQuestion.php @@ -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 = []; diff --git a/src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php b/src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php new file mode 100644 index 0000000000..5ec7a9cacb --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Question/ChoiceQuestionTest.php @@ -0,0 +1,64 @@ + + * + * 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', + ], + ]; + } +} diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index d322d3ff8b..1d1ff321b7 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -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'], diff --git a/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php b/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php index 1b03e0036b..b87fffa82f 100644 --- a/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php +++ b/src/Symfony/Component/Messenger/Tests/TraceableMessageBusTest.php @@ -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__, diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php index ad3c9a5b48..61ce5f1272 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php @@ -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() {