8000 Merge branch '2.8' into 3.1 · symfony/symfony@e1d2426 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1d2426

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: 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 73a7169 + 8a27d79 commit e1d2426

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
@@ -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();
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\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+
};
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+
$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

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;
@@ -65,8 +66,7 @@ public function testValidate()
6566
->setData($object)
6667
->getForm();
6768

68-
$this->expectValidateAt(0, 'data', $object, 'group1');
69-
$this->expectValidateAt(1, 'data', $object, 'group2');
69+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
7070

7171
$this->validator->validate($form, new Form());
7272

@@ -88,12 +88,11 @@ public function testValidateConstraints()
8888
->getForm();
8989

9090
// First default constraints
91-
$this->expectValidateAt(0, 'data', $object, 'group1');
92-
$this->expectValidateAt(1, 'data', $object, 'group2');
91+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
9392

9493
// Then custom constraints
95-
$this->expectValidateValueAt(2, 'data', $object, $constraint1, 'group1');
96-
$this->expectValidateValueAt(3, 'data', $object, $constraint2, 'group2');
94+
$this->expectValidateValueAt(1, 'data', $object, $constraint1, 'group1');
95+
$this->expectValidateValueAt(2, 'data', $object, $constraint2, 'group2');
9796

9897
$this->validator->validate($form, new Form());
9998

@@ -151,7 +150,7 @@ public function testMissingConstraintIndex()
151150
$form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory);
152151
$form = $form->setData($object)->getForm();
153152

154-
$this->expectValidateAt(0, 'data', $object, 'Default');
153+
$this->expectValidateAt(0, 'data', $object, array('Default'));
155154

156155
$this->validator->validate($form, new Form());
157156

@@ -362,6 +361,21 @@ function () { throw new TransformationFailedException(); }
362361
$this->assertNoViolation();
363362
}
364363

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

373-
$this->expectValidateAt(0, 'data', $object, 'group1');
374-
$this->expectValidateAt(1, 'data', $object, 'group2');
387+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
375388

376389
$this->validator->validate($form, new Form());
377390

@@ -386,7 +399,7 @@ public function testDontExecuteFunctionNames()
386399
->setData($object)
387400
->getForm();
388401

389-
$this->expectValidateAt(0, 'data', $object, 'header');
402+
$this->expectValidateAt(0, 'data', $object, array('header'));
390403

391404
$this->validator->validate($form, new Form());
392405

@@ -403,8 +416,7 @@ public function testHandleClosureValidationGroups()
403416
->setData($object)
404417
->getForm();
405418

406-
$this->expectValidateAt(0, 'data', $object, 'group1');
407-
$this->expectValidateAt(1, 'data', $object, 'group2');
419+
$this->expectValidateAt(0, 'data', $object, array('group1', 'group2'));
408420

409421
$this->validator->validate($form, new Form());
410422

@@ -542,7 +554,7 @@ public function testAppendPropertyPath()
542554
->setData($object)
543555
->getForm();
544556

545-
$this->expectValidateAt(0, 'data', $object, 'Default');
557+
$this->expectValidateAt(0, 'data', $object, array('Default'));
546558

547559
$this->validator->validate($form, new Form());
548560

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 <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