8000 Merge branch '3.4' into 4.4 · HeahDude/symfony@44212f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44212f9

Browse files
Merge branch '3.4' into 4.4
* 3.4: Revert "[travis][appveyor] don't cache .phpunit" silence E_NOTICE triggered since PHP 7.4 [Form] Removed legacy check in `ValidationListener` do not merge constraints within interfaces [Validator] Fixed default group for nested composite constraints
2 parents f84592a + 966989a commit 44212f9

File tree

15 files changed

+142
-25
lines changed

15 files changed

+142
-25
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ clone_folder: c:\projects\symfony
44

55
cache:
66
- composer.phar
7+
- .phpunit -> phpunit
78

89
init:
910
- SET PATH=c:\php;%PATH%

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ matrix:
3535

3636
cache:
3737
directories:
38+
- .phpunit
3839
- php-$MIN_PHP
3940
- ~/php-ext
4041

phpunit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env php
22
<?php
33

4+
// Cache-Id: 2020-04-10 20:30 UTC
5+
46
if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
57
echo "Unable to find the `simple-phpunit` script in `vendor/symfony/phpunit-bridge/bin/`.\nPlease run `composer update` before running this command.\n";
68
exit(1);

src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public function validateForm(FormEvent $event)
5050
foreach ($this->validator->validate($form) as $violation) {
5151
// Allow the "invalid" constraint to be put onto
5252
// non-synchronized forms
53-
// ConstraintViolation::getConstraint() must not expect to provide a constraint as long as Symfony\Component\Validator\ExecutionContext exists (before 3.0)
54-
$allowNonSynchronized = (null === $violation->getConstraint() || $violation->getConstraint() instanceof Form) && Form::NOT_SYNCHRONIZED_ERROR === $violation->getCode();
53+
$allowNonSynchronized = $violation->getConstraint() instanceof Form && Form::NOT_SYNCHRONIZED_ERROR === $violation->getCode();
5554

5655
$this->violationMapper->mapViolation($violation, $form, $allowNonSynchronized);
5756
}

src/Symfony/Component/HttpKernel/Log/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function log($level, $message, array $context = [])
7979
}
8080

8181
$formatter = $this->formatter;
82-
fwrite($this->handle, $formatter($level, $message, $context));
82+
@fwrite($this->handle, $formatter($level, $message, $context));
8383
}
8484

8585
private function format(string $level, string $message, array $context): string

src/Symfony/Component/Validator/Constraints/Composite.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public function __construct($options = null)
8888
}
8989
}
9090

91-
$this->groups = array_keys($mergedGroups);
91+
// prevent empty composite constraint to have empty groups
92+
$this->groups = array_keys($mergedGroups) ?: [self::DEFAULT_GROUP];
9293
$this->$compositeOption = $nestedConstraints;
9394

9495
return;

src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,34 +138,25 @@ public function getMetadataFor($value)
138138

139139
private function mergeConstraints(ClassMetadata $metadata)
140140
{
141+
if ($metadata->getReflectionClass()->isInterface()) {
142+
return;
143+
}
144+
141145
// Include constraints from the parent class
142146
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
143147
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
144148
}
145149

146-
$interfaces = $metadata->getReflectionClass()->getInterfaces();
147-
148-
$interfaces = array_filter($interfaces, function (\ReflectionClass $interface) use ($parent, $interfaces) {
149-
$interfaceName = $interface->getName();
150-
151-
if ($parent && $parent->implementsInterface($interfaceName)) {
152-
return false;
153-
}
154-
155-
foreach ($interfaces as $i) {
156-
if ($i !== $interface && $i->implementsInterface($interfaceName)) {
157-
return false;
158-
}
159-
}
160-
161-
return true;
162-
});
163-
164150
// Include constraints from all directly implemented interfaces
165-
foreach ($interfaces as $interface) {
151+
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
166152
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
167153
continue;
168154
}
155+
156+
if ($parent && \in_array($interface->getName(), $parent->getInterfaceNames(), true)) {
157+
continue;
158+
}
159+
169160
$metadata->mergeConstraints($this->getMetadataFor($interface->name));
170161
}
171162
}

src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,16 @@ public function testAcceptRequiredConstraintAsOneElementArray()
100100

101101
$this->assertEquals($collection1, $collection2);
102102
}
103+
104+
public function testConstraintHasDefaultGroupWithOptionalValues()
105+
{
106+
$constraint = new Collection([
107+
'foo' => new Required(),
108+
'bar' => new Optional(),
109+
]);
110+
111+
$this->assertEquals(['Default'], $constraint->groups);
112+
$this->assertEquals(['Default'], $constraint->fields['foo']->groups);
113+
$this->assertEquals(['Default'], $constraint->fields['bar']->groups);
114+
}
103115
}

src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@ public function testExtraFieldsDisallowed()
143143
->assertRaised();
144144
}
145145

146+
public function testExtraFieldsDisallowedWithOptionalValues()
147+
{
148+
$constraint = new Optional();
149+
150+
$data = $this->prepareTestData([
151+
'baz' => 6,
152+
]);
153+
154+
$this->validator->validate($data, new Collection([
155+
'fields' => [
156+
'foo' => $constraint,
157+
],
158+
'extraFieldsMessage' => 'myMessage',
159+
]));
160+
161+
$this->buildViolation('myMessage')
162+
->setParameter('{{ field }}', '"baz"')
163+
->atPath('property.path[baz]')
164+
->setInvalidValue(6)
165+
->setCode(Collection::NO_SUCH_FIELD_ERROR)
166+
->assertRaised();
167+
}
168+
146169
// bug fix
147170
public function testNullNotConsideredExtraField()
148171
{

src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
class ConcreteComposite extends Composite
2121
{
22-
public $constraints;
22+
public $constraints = [];
2323

2424
protected function getCompositeOption(): string
2525
{
@@ -37,6 +37,30 @@ public function getDefaultOption(): ?string
3737
*/
3838
class CompositeTest extends TestCase
3939
{
40+
public function testConstraintHasDefaultGroup()
41+
{
42+
$constraint = new ConcreteComposite([
43+
new NotNull(),
44+
new NotBlank(),
45+
]);
46+
47+
$this->assertEquals(['Default'], $constraint->groups);
48+
$this->assertEquals(['Default'], $constraint->constraints[0]->groups);
49+
$this->assertEquals(['Default'], $constraint->constraints[1]->groups);
50+
}
51+
52+
public function testNestedCompositeConstraintHasDefaultGroup()
53+
{
54+
$constraint = new ConcreteComposite([
55+
new ConcreteComposite(),
56+
new ConcreteComposite(),
57+
]);
58+
59+
$this->assertEquals(['Default'], $constraint->groups);
60+
$this->assertEquals(['Default'], $constraint->constraints[0]->groups);
61+
$this->assertEquals(['Default'], $constraint->constraints[1]->groups);
62+
}
63+
4064
public function testMergeNestedGroupsIfNoExplicitParentGroup()
4165
{
4266
$constraint = new ConcreteComposite([

0 commit comments

Comments
 (0)
0