Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a27d79

Browse filesBrowse files
committed
Merge branch '2.7' into 2.8
* 2.7: use HHVM 3.15 to run tests [TwigBridge] fix Twig 2.x compatibility removed some PHP CS Fixer rules Improve language [Console] SymfonyStyle: Escape trailing backslashes in user texts Mention the community review guide [Form] fix group sequence based validation [Console] Fix question formatting using SymfonyStyle::ask()
2 parents ab520a1 + 9f18585 commit 8a27d79
Copy full SHA for 8a27d79

File tree

Expand file treeCollapse file tree

16 files changed

+138
-49
lines changed
Filter options
Expand file treeCollapse file tree

16 files changed

+138
-49
lines changed

‎.php_cs.dist

Copy file name to clipboardExpand all lines: .php_cs.dist
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ return PhpCsFixer\Config::create()
55
'@Symfony' => true,
66
'@Symfony:risky' => true,
77
'array_syntax' => array('syntax' => 'long'),
8+
'no_unreachable_default_argument_value' => false,
9+
'heredoc_to_nowdoc' => false,
810
))
911
->setRiskyAllowed(true)
1012
->setFinder(

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
matrix:
1919
include:
2020
# Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
21-
- php: hhvm-stable
21+
- php: hhvm-3.15
2222
sudo: required
2323
dist: trusty
2424
group: edge

‎CONTRIBUTING.md

Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Symfony is an open source, community-driven project.
55

66
If you'd like to contribute, please read the following documents:
77

8+
* [Reviewing issues/pull requests][0]
89
* [Reporting a Bug][1]
910
* [Submitting a Patch][2]
1011
* [Symfony Core Team][3]
@@ -14,6 +15,7 @@ If you'd like to contribute, please read the following documents:
1415
* [Coding Standards][7]
1516
* [Conventions][8]
1617

18+
[0]: https://symfony.com/doc/current/contributing/community/reviews.html
1719
[1]: https://symfony.com/doc/current/contributing/code/bugs.html
1820
[2]: https://symfony.com/doc/current/contributing/code/patches.html
1921
[3]: https://symfony.com/doc/current/contributing/code/core_team.html

‎README.md

Copy file name to clipboardExpand all lines: README.md
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ please read the [Contributing Code][3] part of the documentation. If you're subm
4141
a pull request, please follow the guidelines in the [Submitting a Patch][4] section
4242
and use [Pull Request Template][5].
4343

44+
Community Reviews
45+
-----------------
46+
47+
If you don't feel ready to contribute code or patches, reviewing issues and pull
48+
requests can be a great start to get involved and give back. In fact, people who
49+
"triage" issues are the backbone to Symfony's success!
50+
More information can be found in the [Community Reviews][8] guide.
51+
4452
Running Symfony Tests
4553
----------------------
4654

@@ -54,3 +62,4 @@ Information on how to run the Symfony test suite can be found in the
5462
[5]: https://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request
5563
[6]: https://symfony.com/doc/master/contributing/code/tests.html
5664
[7]: https://symfony.com/doc/current/book/installation.html#installing-the-symfony-installer
65+
[8]: https://symfony.com/doc/current/contributing/community/reviews.html

‎src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function getVariableGetterWithoutStrictCheck($name)
5353
protected function getVariableGetterWithStrictCheck($name)
5454
{
5555
if (\Twig_Environment::MAJOR_VERSION >= 2) {
56-
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name);
56+
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : (function () { throw new Twig_Error_Runtime(\'Variable "%s" does not exist.\', 0, $this->getSourceContext()); })())', $name, $name, $name, $name);
5757
}
5858

5959
if (PHP_VERSION_ID >= 70000) {

‎src/Symfony/Component/Console/Formatter/OutputFormatter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Formatter/OutputFormatter.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ public static function escape($text)
3535
{
3636
$text = preg_replace('/([^\\\\]?)</', '$1\\<', $text);
3737

38+
return self::escapeTrailingBackslash($text);
39+
}
40+
41+
/**
42+
* Escapes trailing "\" in given text.
43+
*
44+
* @param string $text Text to escape
45+
*
46+
* @return string Escaped text
47+
*
48+
* @internal
49+
*/
50+
public static function escapeTrailingBackslash($text)
51+
{
3852
if ('\\' === substr($text, -1)) {
3953
$len = strlen($text);
4054
$text = rtrim($text, '\\');

‎src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
5454
*/
5555
protected function writePrompt(OutputInterface $output, Question $question)
5656
{
57-
$text = OutputFormatter::escape($question->getQuestion());
57+
$text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
5858
$default = $question->getDefault();
5959

6060
switch (true) {

‎src/Symfony/Component/Console/Style/SymfonyStyle.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Style/SymfonyStyle.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function title($message)
7979
{
8080
$this->autoPrependBlock();
8181
$this->writeln(array(
82-
sprintf('<comment>%s</>', $message),
82+
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
8383
sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
8484
));
8585
$this->newLine();
@@ -92,7 +92,7 @@ public function section($message)
9292
{
9393
$this->autoPrependBlock();
9494
$this->writeln(array(
95-
sprintf('<comment>%s</>', $message),
95+
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
9696
sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
9797
));
9898
$this->newLine();
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
//Ensure symfony style helper methods handle trailing backslashes properly when decorating user texts
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
10+
11+
$output->title('Title ending with \\');
12+
$output->section('Section ending with \\');
13+
};
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
Title ending with \
3+
===================
4+
5+
Section ending with \
6+
---------------------
7+

‎src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,22 @@ public function testAskEscapeDefaultValue()
9292
$this->assertOutputContains('Can I have a backslash? [\]', $output);
9393
}
9494

95-
public function testAskEscapeLabel()
95+
public function testAskEscapeAndFormatLabel()
96+
{
97+
$helper = new SymfonyQuestionHelper();
98+
$helper->setInputStream($this->getInputStream('Foo\\Bar'));
99+
$helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Do you want to use Foo\\Bar <comment>or</comment> Foo\\Baz\\?', 'Foo\\Baz'));
100+
101+
$this->assertOutputContains('Do you want to use Foo\\Bar or Foo\\Baz\\? [Foo\\Baz]:', $output);
102+
}
103+
104+
public function testLabelTrailingBackslash()
96105
{
97106
$helper = new SymfonyQuestionHelper();
98107
$helper->setInputStream($this->getInputStream('sure'));
99-
$helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Do you want a \?'));
108+
$helper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), new Question('Question with a trailing \\'));
100109

101-
$this->assertOutputContains('Do you want a \?', $output);
110+
$this->assertOutputContains('Question with a trailing \\', $output);
102111
}
103112

104113
/**

‎src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Form\FormInterface;
1515
use Symfony\Component\Validator\Constraint;
16+
use Symfony\Component\Validator\Constraints\GroupSequence;
1617
use Symfony\Component\Validator\Constraints\Valid;
1718
use Symfony\Component\Validator\ConstraintValidator;
1819
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -50,10 +51,12 @@ public function validate($form, Constraint $constraint)
5051

5152
// Validate the data against its own constraints
5253
if (self::allowDataWalking($form)) {
53-
foreach ($groups as $group) {
54-
if ($validator) {
55-
$validator->atPath('data')->validate($form->getData(), null, $group);
56-
} else {
54+
if ($validator) {
55+
if (is_array($groups) && count($groups) > 0 || $groups instanceof GroupSequence && count($groups->groups) > 0) {
56+
$validator->atPath('data')->validate($form->getData(), null, $groups);
57+
}
58+
} else {
59+
foreach ($groups as $group) {
5760
// 2.4 API
5861
$this->context->validate($form->getData(), 'data', $group, true);
5962
}
@@ -233,6 +236,10 @@ private static function resolveValidationGroups($groups, FormInterface $form)
233236
$groups = call_user_func($groups, $form);
234237
}
235238

239+
if ($groups instanceof GroupSequence) {
240+
return $groups;
241+
}
242+
236243
return (array) $groups;
237244
}
238245
}

‎src/Symfony/Component/Form/Extension/Validator/Type/BaseValidatorExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/Type/BaseValidatorExtension.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\AbstractTypeExtension;
1515
use Symfony\Component\OptionsResolver\Options;
1616
use Symfony\Component\OptionsResolver\OptionsResolver;
17+
use Symfony\Component\Validator\Constraints\GroupSequence;
1718

1819
/**
1920
* Encapsulates common logic of {@link FormTypeValidatorExtension} and
@@ -42,6 +43,10 @@ public function configureOptions(OptionsResolver $resolver)
4243
return $groups;
4344
}
4445

46+
if ($groups instanceof GroupSequence) {
47+
return $groups;
48+
}
49+
4550
return (array) $groups;
4651
};
4752

‎src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php
+26-15Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
1919
use Symfony\Component\Form\Extension\Validator\Constraints\FormValidator;
2020
use Symfony\Component\Form\SubmitButtonBuilder;
21+
use Symfony\Component\Validator\Constraints\GroupSequence;
2122
use Symfony\Component\Validator\Constraints\NotNull;
2223
use Symfony\Component\Validator\Constraints\NotBlank;
2324
use Symfony\Component\Validator\Constraints\Valid;
@@ -72,8 +73,7 @@ public function testValidate()
7273
->setData($object)
7374
->getForm();
7475

75-
$this->expectValidateAt(0, 'data', $object, 'group1');
76-
$this->expectValidateAt(1, 'data', $object, 'group2');
76+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
7777

7878
$this->validator->validate($form, new Form());
7979

@@ -95,12 +95,11 @@ public function testValidateConstraints()
9595
->getForm();
9696

9797
// First default constraints
98-
$this->expectValidateAt(0, 'data', $object, 'group1');
99-
$this->expectValidateAt(1, 'data', $object, 'group2');
98+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
10099

101100
// Then custom constraints
102-
$this->expectValidateValueAt(2, 'data', $object, $constraint1, 'group1');
103-
$this->expectValidateValueAt(3, 'data', $object, $constraint2, 'group2');
101+
$this->expectValidateValueAt(1, 'data', $object, $constraint1, 'group1');
102+
$this->expectValidateValueAt(2, 'data', $object, $constraint2, 'group2');
104103

105104
$this->validator->validate($form, new Form());
106105

@@ -121,8 +120,7 @@ public function testValidateIfParentWithCascadeValidation()
121120

122121
$form->setData($object);
123122

124-
$this->expectValidateAt(0, 'data', $object, 'group1');
125-
$this->expectValidateAt(1, 'data', $object, 'group2');
123+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
126124

127125
$this->validator->validate($form, new Form());
128126

@@ -180,7 +178,7 @@ public function testMissingConstraintIndex()
180178
$form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory);
181179
$form = $form->setData($object)->getForm();
182180

183-
$this->expectValidateAt(0, 'data', $object, 'Default');
181+
$this->expectValidateAt(0, 'data', $object, array('Default'));
184182

185183
$this->validator->validate($form, new Form());
186184

@@ -392,15 +390,29 @@ function () { throw new TransformationFailedException(); }
392390
}
393391

394392
public function testHandleCallbackValidationGroups()
393+
{
394+
$object = $this->getMockBuilder('\stdClass')->getMock();
395+
$options = array('validation_groups' => new GroupSequence(array('group1', 'group2')));
396+
$form = $this->getBuilder('name', '\stdClass', $options)
397+
->setData($object)
398+
->getForm();
399+
400+
$this->expectValidateAt(0, 'data', $object, new GroupSequence(array('group1', 'group2')));
401+
402+
$this->validator->validate($form, new Form());
403+
404+
$this->assertNoViolation();
405+
}
406+
407+
public function testHandleGroupSequenceValidationGroups()
395408
{
396409
$object = $this->getMockBuilder('\stdClass')->getMock();
397410
$options = array('validation_groups' => array($this, 'getValidationGroups'));
398411
$form = $this->getBuilder('name', '\stdClass', $options)
399412
->setData($object)
400413
->getForm();
401414

402-
$this->expectValidateAt(0, 'data', $object, 'group1');
403-
$this->expectValidateAt(1, 'data', $object, 'group2');
415+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
404416

405417
$this->validator->validate($form, new Form());
406418

@@ -415,7 +427,7 @@ public function testDontExecuteFunctionNames()
415427
->setData($object)
416428
->getForm();
417429

418-
$this->expectValidateAt(0, 'data', $object, 'header');
430+
$this->expectValidateAt(0, 'data', $object, array('header'));
419431

420432
$this->validator->validate($form, new Form());
421433

@@ -432,8 +444,7 @@ public function testHandleClosureValidationGroups()
432444
->setData($object)
433445
->getForm();
434446

435-
$this->expectValidateAt(0, 'data', $object, 'group1');
436-
$this->expectValidateAt(1, 'data', $object, 'group2');
447+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
437448

438449
$this->validator->validate($form, new Form());
439450

@@ -571,7 +582,7 @@ public function testAppendPropertyPath()
571582
->setData($object)
572583
->getForm();
573584

574-
$this->expectValidateAt(0, 'data', $object, 'Default');
585+
$this->expectValidateAt(0, 'data', $object, array('Default'));
575586

576587
$this->validator->validate($form, new Form());
577588

‎src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/Type/BaseValidatorExtensionTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
1313

1414
use Symfony\Component\Form\Test\FormInterface;
15+
use Symfony\Component\Validator\Constraints\GroupSequence;
1516

1617
/**
1718
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -70,5 +71,14 @@ public function testValidationGroupsCanBeSetToClosure()
7071
$this->assertInternalType('callable', $form->getConfig()->getOption('validation_groups'));
7172
}
7273

74+
public function testValidationGroupsCanBeSetToGroupSequence()
75+
{
76+
$form = $this->createForm(array(
77+
'validation_groups' => new GroupSequence(array('group1', 'group2')),
78+
));
79+
80+
$this->assertInstanceOf('Symfony\Component\Validator\Constraints\GroupSequence', $form->getConfig()->getOption('validation_groups'));
81+
}
82+
7383
abstract protected function createForm(array $options = array());
7484
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.