Merge branch '3.2'

* 3.2:
  fixed tests
  fixed tests
  revert typo fix
  [Form] Fix ChoiceType to ensure submitted data is not nested unnecessarily
  Fix phpstorm helper to the official format
  Test inline styles with non-decorated formatter
  Fix RuntimeException when an Emacs buffer is modified
  [Yaml] add tests for specific mapping keys
This commit is contained in:
Fabien Potencier 2017-03-01 10:19:35 -08:00
commit 8d99d5758a
6 changed files with 71 additions and 3 deletions

View File

@ -131,7 +131,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'];

View File

@ -90,8 +90,15 @@ class DirectoryResource implements SelfCheckingResourceInterface, \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;
}
}

View File

@ -257,6 +257,9 @@ class OutputFormatterTest extends TestCase
$this->assertEquals(
'some question', $formatter->format('<question>some question</question>')
);
$this->assertEquals(
'some text with inline style', $formatter->format('<fg=red>some text with inline style</>')
);
$formatter->setDecorated(true);
@ -272,6 +275,9 @@ class OutputFormatterTest extends TestCase
$this->assertEquals(
"\033[30;46msome question\033[39;49m", $formatter->format('<question>some question</question>')
);
$this->assertEquals(
"\033[31msome text with inline style\033[39m", $formatter->format('<fg=red>some text with inline style</>')
);
}
public function testContentWithLineBreaks()

View File

@ -156,6 +156,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);
}
/**

View File

@ -13,8 +13,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;
class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
class ChoiceTypeTest extends TypeTestCase
{
private $choices = array(
'Bernhard' => 'a',
@ -1743,4 +1745,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('Symfony\Component\Form\Extension\Core\Type\ChoiceType', 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())),
);
}
}

View File

@ -718,4 +718,15 @@ class InlineTest extends TestCase
'null before comma' => array('{foo:, bar: baz}', array('foo' => null, 'bar' => 'baz')),
);
}
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 }'));
}
}