From b8e0d705f674533ee0e688184a0544ad59fc6e84 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Feb 2017 14:04:52 +0100 Subject: [PATCH 1/8] =?UTF-8?q?[Yaml]=C2=A0add=20tests=20for=20specific=20?= =?UTF-8?q?mapping=20keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Symfony/Component/Yaml/Tests/InlineTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 56966bacd3..ab8bbed74c 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -420,4 +420,15 @@ class InlineTest extends \PHPUnit_Framework_TestCase $this->assertEquals($longStringWithQuotes, $arrayFromYaml['longStringWithQuotes']); } + + public function testBooleanMappingKeysAreConvertedToStrings() + { + $this->assertSame(array('false' => 'foo'), Inline::parse('{false: foo}')); + $this->assertSame(array('true' => 'foo'), Inline::parse('{true: foo}')); + } + + public function testTheEmptyStringIsAValidMappingKey() + { + $this->assertSame(array('' => 'foo'), Inline::parse('{ "": foo }')); + } } From c6f7ca6fa1f14eb8db6b1aa33fe45c9e542b6e8e Mon Sep 17 00:00:00 2001 From: rubenrua Date: Thu, 23 Feb 2017 14:04:10 +0100 Subject: [PATCH 2/8] Fix RuntimeException when an Emacs buffer is modified When an Emacs buffer is modified, by default Emacs automatically creates a temporary symlink in the same directory as the file being edited (e.g. Controller.php): ``` .#Controller.php -> user@host.12345:1296583136 ``` where '12345' is Emacs' PID. In this case Symfony breaks with a RuntimeException: ``` SplFileInfo::getMTime(): stat failed for ...Bundle/Controller/.#APIController.php ``` in vendor/symfony/symfony/src/Symfony/Component/Config/Resource/DirectoryResource.php at line 89 ``` $newestMTime = max($file->getMTime(), $newestMTime); ``` --- .../Component/Config/Resource/DirectoryResource.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Resource/DirectoryResource.php b/src/Symfony/Component/Config/Resource/DirectoryResource.php index e403725d6a..bde84b1b5b 100644 --- a/src/Symfony/Component/Config/Resource/DirectoryResource.php +++ b/src/Symfony/Component/Config/Resource/DirectoryResource.php @@ -84,8 +84,15 @@ class DirectoryResource implements ResourceInterface, \Serializable continue; } + // for broken links + try { + $fileMTime = $file->getMTime(); + } catch (\RuntimeException $e) { + continue; + } + // early return if a file's mtime exceeds the passed timestamp - if ($timestamp < $file->getMTime()) { + if ($timestamp < $fileMTime) { return false; } } From 8530e055742f042c72a6000bfc5adae5b0fe1676 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Tue, 28 Feb 2017 19:03:12 +0100 Subject: [PATCH 3/8] Test inline styles with non-decorated formatter --- .../Console/Tests/Formatter/OutputFormatterTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index dc7b0358de..866c31a443 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -196,6 +196,9 @@ class OutputFormatterTest extends TestCase $this->assertEquals( 'some question', $formatter->format('some question') ); + $this->assertEquals( + 'some text with inline style', $formatter->format('some text with inline style') + ); $formatter->setDecorated(true); @@ -211,6 +214,9 @@ class OutputFormatterTest extends TestCase $this->assertEquals( "\033[30;46msome question\033[39;49m", $formatter->format('some question') ); + $this->assertEquals( + "\033[31msome text with inline style\033[39m", $formatter->format('some text with inline style') + ); } public function testContentWithLineBreaks() From eb09d7cc2ed590fe79c598d58cc01b57d920cf8c Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Wed, 1 Mar 2017 16:46:28 +0200 Subject: [PATCH 4/8] Fix phpstorm helper to the official format --- .../FrameworkBundle/DependencyInjection/FrameworkExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index cfe687ad35..60cbd4fd48 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -110,7 +110,7 @@ class FrameworkExtension extends Extension 'macvim' => 'mvim://open?url=file://%%f&line=%%l', 'emacs' => 'emacs://open?url=file://%%f&line=%%l', 'sublime' => 'subl://open?url=file://%%f&line=%%l', - 'phpstorm' => 'phpstorm://open?url=file://%%f&line=%%l', + 'phpstorm' => 'phpstorm://open?file=%%f&line=%%l', ); $ide = $config['ide']; From 64d7a82d28a79c98a203ae38b1bb305081cfdf34 Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Fri, 13 Jan 2017 14:08:30 +0900 Subject: [PATCH 5/8] [Form] Fix ChoiceType to ensure submitted data is not nested unnecessarily --- .../Form/Extension/Core/Type/ChoiceType.php | 20 +++++++++++-- .../Extension/Core/Type/ChoiceTypeTest.php | 29 ++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index d376109828..489d5d77d7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -160,6 +160,22 @@ class ChoiceType extends AbstractType // transformation is merged back into the original collection $builder->addEventSubscriber(new MergeCollectionListener(true, true)); } + + // To avoid issues when the submitted choices are arrays (i.e. array to string conversions), + // we have to ensure that all elements of the submitted choice data are strings or null. + $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + $data = $event->getData(); + + if (!is_array($data)) { + return; + } + + foreach ($data as $v) { + if (null !== $v && !is_string($v)) { + throw new TransformationFailedException('All choices submitted must be NULL or strings.'); + } + } + }, 256); } /** @@ -505,8 +521,8 @@ class ChoiceType extends AbstractType * "choice_label" closure by default. * * @param array|\Traversable $choices The choice labels indexed by choices - * @param object $choiceLabels The object that receives the choice labels - * indexed by generated keys. + * @param object $choiceLabels the object that receives the choice labels + * indexed by generated keys * @param int $nextKey The next generated key * * @return array The choices in a normalized array with labels replaced by generated keys diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index b675d5d6ee..10adffbecc 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -14,9 +14,10 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList; +use Symfony\Component\Form\Test\TypeTestCase; use Symfony\Component\Form\Tests\Fixtures\ChoiceSubType; -class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase +class ChoiceTypeTest extends TypeTestCase { private $choices = array( 'Bernhard' => 'a', @@ -2283,4 +2284,30 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase // In this case the 'choice_label' closure returns null and not the closure from the first choice type. $this->assertNull($form->get('subChoice')->getConfig()->getOption('choice_label')); } + + /** + * @dataProvider invalidNestedValueTestMatrix + */ + public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionData) + { + $form = $this->factory->create('choice', null, array( + 'choices' => $this->choices, + 'multiple' => $multiple, + 'expanded' => $expanded, + )); + + $form->submit($submissionData); + $this->assertFalse($form->isSynchronized()); + $this->assertEquals('All choices submitted must be NULL or strings.', $form->getTransformationFailure()->getMessage()); + } + + public function invalidNestedValueTestMatrix() + { + return array( + 'non-multiple, non-expanded' => array(false, false, array(array())), + 'non-multiple, expanded' => array(false, true, array(array())), + 'multiple, non-expanded' => array(true, false, array(array())), + 'multiple, expanded' => array(true, true, array(array())), + ); + } } From a786b5aaaf300b36b93d1faae1ae47475de8f82e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 1 Mar 2017 06:59:13 -0800 Subject: [PATCH 6/8] revert typo fix --- src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 489d5d77d7..b4b820ef26 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -521,7 +521,7 @@ class ChoiceType extends AbstractType * "choice_label" closure by default. * * @param array|\Traversable $choices The choice labels indexed by choices - * @param object $choiceLabels the object that receives the choice labels + * @param object $choiceLabels The object that receives the choice labels * indexed by generated keys * @param int $nextKey The next generated key * From 4b27628bcabf2f0ec0c0976414bb598b531b46ea Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 1 Mar 2017 10:16:08 -0800 Subject: [PATCH 7/8] fixed tests --- .../Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 54e65f6cfe..b3fd99f950 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -2305,10 +2305,11 @@ class ChoiceTypeTest extends TypeTestCase */ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionData) { - $form = $this->factory->create('choice', null, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->choices, 'multiple' => $multiple, 'expanded' => $expanded, + 'choices_as_values' => true, )); $form->submit($submissionData); From 120f29344da0f741c9f20ff0e6006610e3a98e7b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 1 Mar 2017 10:18:36 -0800 Subject: [PATCH 8/8] fixed tests --- .../Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 5ecaa1a421..864e670a6e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -1755,7 +1755,6 @@ class ChoiceTypeTest extends TypeTestCase 'choices' => $this->choices, 'multiple' => $multiple, 'expanded' => $expanded, - 'choices_as_values' => true, )); $form->submit($submissionData);