Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bc268e

Browse files
committed
Merge branch '3.2'
* 3.2: 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 5c5c911 + a3788e7 commit 7bc268e

File tree

16 files changed

+133
-45
lines changed

16 files changed

+133
-45
lines changed

.php_cs.dist

Lines 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ env:
2020
matrix:
2121
include:
2222
# Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
23-
- php: hhvm-stable
23+
- php: hhvm-3.15
2424
sudo: required
2525
dist: trusty
2626
group: edge

CONTRIBUTING.md

Lines 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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ please read the [Contributing Code][3] part of the documentation. If you're subm
3333
a pull request, please follow the guidelines in the [Submitting a Patch][4] section
3434
and use [Pull Request Template][5].
3535

36+
Community Reviews
37+
-----------------
38+
39+
If you don't feel ready to contribute code or patches, reviewing issues and pull
40+
requests can be a great start to get involved and give back. In fact, people who
41+
"triage" issues are the backbone to Symfony's success!
42+
More information can be found in the [Community Reviews][8] guide.
43+
3644
Running Symfony Tests
3745
----------------------
3846

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function getVariableGetterWithoutStrictCheck($name)
4949
protected function getVariableGetterWithStrictCheck($name)
5050
{
5151
if (\Twig_Environment::MAJOR_VERSION >= 2) {
52-
return sprintf('(isset($context["%s"]) || array_key_exists("%s", $context) ? $context["%s"] : $this->notFound("%s", 0))', $name, $name, $name, $name);
52+
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);
5353
}
5454

5555
if (PHP_VERSION_ID >= 70000) {

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

Lines 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

Lines 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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function title($message)
8080
{
8181
$this->autoPrependBlock();
8282
$this->writeln(array(
83-
sprintf('<comment>%s</>', $message),
83+
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
8484
sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
8585
));
8686
$this->newLine();
@@ -93,7 +93,7 @@ public function section($message)
9393
{
9494
$this->autoPrependBlock();
9595
$this->writeln(array(
96-
sprintf('<comment>%s</>', $message),
96+
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
9797
sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
9898
));
9999
$this->newLine();
Lines 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\Style\SymfonyStyle;
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 SymfonyStyle($input, $output);
10+
11+
$output->title('Title ending with \\');
12+
$output->section('Section ending with \\');
13+
};
Lines 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

Lines 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+
$input = $this->createStreamableInputInterfaceMock($this->getInputStream('Foo\\Bar'));
99+
$helper->ask($input, $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
$input = $this->createStreamableInputInterfaceMock($this->getInputStream('sure'));
99-
$helper->ask($input, $output = $this->createOutputInterface(), new Question('Do you want a \?'));
108+
$helper->ask($input, $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

Lines changed: 7 additions & 2 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\Exception\UnexpectedTypeException;
@@ -47,8 +48,8 @@ public function validate($form, Constraint $constraint)
4748

4849
// Validate the data against its own constraints
4950
if ($form->isRoot() && (is_object($data) || is_array($data))) {
50-
foreach ($groups as $group) {
51-
$validator->atPath('data')->validate($form->getData(), null, $group);
51+
if (is_array($groups) && count($groups) > 0 || $groups instanceof GroupSequence && count($groups->groups) > 0) {
52+
$validator->atPath('data')->validate($form->getData(), null, $groups);
5253
}
5354
}
5455

@@ -166,6 +167,10 @@ private static function resolveValidationGroups($groups, FormInterface $form)
166167
$groups = call_user_func($groups, $form);
167168
}
168169

170+
if ($groups instanceof GroupSequence) {
171+
return $groups;
172+
}
173+
169174
return (array) $groups;
170175
}
171176
}

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

Lines 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

Lines changed: 25 additions & 13 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;
@@ -67,8 +68,7 @@ public function testValidate()
6768
->setData($object)
6869
->getForm();
6970

70-
$this->expectValidateAt(0, 'data', $object, 'group1');
71-
$this->expectValidateAt(1, 'data', $object, 'group2');
71+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
7272

7373
$this->validator->validate($form, new Form());
7474

@@ -90,12 +90,11 @@ public function testValidateConstraints()
9090
->getForm();
9191

9292
// First default constraints
93-
$this->expectValidateAt(0, 'data', $object, 'group1');
94-
$this->expectValidateAt(1, 'data', $object, 'group2');
93+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
9594

9695
// Then custom constraints
97-
$this->expectValidateValueAt(2, 'data', $object, $constraint1, 'group1');
98-
$this->expectValidateValueAt(3, 'data', $object, $constraint2, 'group2');
96+
$this->expectValidateValueAt(1, 'data', $object, $constraint1, 'group1');
97+
$this->expectValidateValueAt(2, 'data', $object, $constraint2, 'group2');
9998

10099
$this->validator->validate($form, new Form());
101100

@@ -153,7 +152,7 @@ public function testMissingConstraintIndex()
153152
$form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory);
154153
$form = $form->setData($object)->getForm();
155154

156-
$this->expectValidateAt(0, 'data', $object, 'Default');
155+
$this->expectValidateAt(0, 'data', $object, array('Default'));
157156

158157
$this->validator->validate($form, new Form());
159158

@@ -364,6 +363,21 @@ function () { throw new TransformationFailedException(); }
364363
$this->assertNoViolation();
365364
}
366365

366+
public function testHandleGroupSequenceValidationGroups()
367+
{
368+
$object = $this->getMockBuilder('\stdClass')->getMock();
369+
$options = array('validation_groups' => new GroupSequence(array('group1', 'group2')));
370+
$form = $this->getBuilder('name', '\stdClass', $options)
371+
->setData($object)
372+
->getForm();
373+
374+
$this->expectValidateAt(0, 'data', $object, new GroupSequence(array('group1', 'group2')));
375+
376+
$this->validator->validate($form, new Form());
377+
378+
$this->assertNoViolation();
379+
}
380+
367381
public function testHandleCallbackValidationGroups()
368382
{
369383
$object = $this->getMockBuilder('\stdClass')->getMock();
@@ -372,8 +386,7 @@ public function testHandleCallbackValidationGroups()
372386
->setData($object)
373387
->getForm();
374388

375-
$this->expectValidateAt(0, 'data', $object, 'group1');
376-
$this->expectValidateAt(1, 'data', $object, 'group2');
389+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
377390

378391
$this->validator->validate($form, new Form());
379392

@@ -388,7 +401,7 @@ public function testDontExecuteFunctionNames()
388401
->setData($object)
389402
->getForm();
390403

391-
$this->expectValidateAt(0, 'data', $object, 'header');
404+
$this->expectValidateAt(0, 'data', $object, array('header'));
392405

393406
$this->validator->validate($form, new Form());
394407

@@ -405,8 +418,7 @@ public function testHandleClosureValidationGroups()
405418
->setData($object)
406419
->getForm();
407420

408-
$this->expectValidateAt(0, 'data', $object, 'group1');
409-
$this->expectValidateAt(1, 'data', $object, 'group2');
421+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
410422

411423
$this->validator->validate($form, new Form());
412424

@@ -544,7 +556,7 @@ public function testAppendPropertyPath()
544556
->setData($object)
545557
->getForm();
546558

547-
$this->expectValidateAt(0, 'data', $object, 'Default');
559+
$this->expectValidateAt(0, 'data', $object, array('Default'));
548560

549561
$this->validator->validate($form, new Form());
550562

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

Lines 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 <[email protected]>
@@ -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)