Skip to content

Commit e4d9e66

Browse files
Merge branch '5.4' into 6.0
* 5.4: [Messenger] Remove redundant interface in DoctrineReceiver Fix choice filter error when loading mix of grouped and non-grouped choices [Mime] Allow url as a path in the DataPart::fromPath Fix getting class constraints on debug command
2 parents be1da04 + 3034905 commit e4d9e66

File tree

2 files changed

+102
-53
lines changed

2 files changed

+102
-53
lines changed

Command/DebugCommand.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,19 @@ private function dumpValidatorsForClass(InputInterface $input, OutputInterface $
8888
$rows = [];
8989
$dump = new Dumper($output);
9090

91-
foreach ($this->getConstrainedPropertiesData($class) as $propertyName => $constraintsData) {
91+
/** @var ClassMetadataInterface $classMetadata */
92+
$classMetadata = $this->validator->getMetadataFor($class);
93+
94+
foreach ($this->getClassConstraintsData($classMetadata) as $data) {
95+
$rows[] = [
96+
'-',
97+
$data['class'],
98+
implode(', ', $data['groups']),
99+
$dump($data['options']),
100+
];
101+
}
102+
103+
foreach ($this->getConstrainedPropertiesData($classMetadata) as $propertyName => $constraintsData) {
92104
foreach ($constraintsData as $data) {
93105
$rows[] = [
94106
$propertyName,
@@ -119,12 +131,20 @@ private function dumpValidatorsForClass(InputInterface $input, OutputInterface $
119131
$table->render();
120132
}
121133

122-
private function getConstrainedPropertiesData(string $class): array
134+
private function getClassConstraintsData(ClassMetadataInterface $classMetadata): iterable
123135
{
124-
$data = [];
136+
foreach ($classMetadata->getConstraints() as $constraint) {
137+
yield [
138+
'class' => \get_class($constraint),
139+
'groups' => $constraint->groups,
140+
'options' => $this->getConstraintOptions($constraint),
141+
];
142+
}
143+
}
125144

126-
/** @var ClassMetadataInterface $classMetadata */
127-
$classMetadata = $this->validator->getMetadataFor($class);
145+
private function getConstrainedPropertiesData(ClassMetadataInterface $classMetadata): array
146+
{
147+
$data = [];
128148

129149
foreach ($classMetadata->getConstrainedProperties() as $constrainedProperty) {
130150
$data[$constrainedProperty] = $this->getPropertyData($classMetadata, $constrainedProperty);

Tests/Command/DebugCommandTest.php

Lines changed: 77 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Tester\CommandTester;
1616
use Symfony\Component\Validator\Command\DebugCommand;
1717
use Symfony\Component\Validator\Constraints\Email;
18+
use Symfony\Component\Validator\Constraints\Expression;
1819
use Symfony\Component\Validator\Constraints\NotBlank;
1920
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
2021
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
@@ -38,6 +39,11 @@ public function testOutputWithClassArgument()
3839
->with(DummyClassOne::class)
3940
->willReturn($classMetadata);
4041

42+
$classMetadata
43+
->expects($this->once())
44+
->method('getConstraints')
45+
->willReturn([new Expression('1 + 1 = 2')]);
46+
4147
$classMetadata
4248
->expects($this->once())
4349
->method('getConstrainedProperties')
@@ -68,22 +74,28 @@ public function testOutputWithClassArgument()
6874
Symfony\Component\Validator\Tests\Dummy\DummyClassOne
6975
-----------------------------------------------------
7076
71-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
72-
| Property | Name | Groups | Options |
73-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
74-
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | [ |
75-
| | | | "allowNull" => false, |
76-
| | | | "message" => "This value should not be blank.", |
77-
| | | | "normalizer" => null, |
78-
| | | | "payload" => null |
79-
| | | | ] |
80-
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | [ |
81-
| | | | "message" => "This value is not a valid email address.", |
82-
| | | | "mode" => null, |
83-
| | | | "normalizer" => null, |
84-
| | | | "payload" => null |
85-
| | | | ] |
86-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
77+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
78+
| Property | Name | Groups | Options |
79+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
80+
| - | Symfony\Component\Validator\Constraints\Expression | Default | [ |
81+
| | | | "expression" => "1 + 1 = 2", |
82+
| | | | "message" => "This value is not valid.", |
83+
| | | | "payload" => null, |
84+
| | | | "values" => [] |
85+
| | | | ] |
86+
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | [ |
87+
| | | | "allowNull" => false, |
88+
| | | | "message" => "This value should not be blank.", |
89+
| | | | "normalizer" => null, |
90+
| | | | "payload" => null |
91+
| | | | ] |
92+
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | [ |
93+
| | | | "message" => "This value is not a valid email address.", |
94+
| | | | "mode" => null, |
95+
| | | | "normalizer" => null, |
96+
| | | | "payload" => null |
97+
| | | | ] |
98+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
8799
88100
TXT
89101
, $tester->getDisplay(true)
@@ -108,6 +120,11 @@ public function testOutputWithPathArgument()
108120
'firstArgument',
109121
]);
110122

123+
$classMetadata
124+
->expects($this->exactly(2))
125+
->method('getConstraints')
126+
->willReturn([new Expression('1 + 1 = 2')]);
127+
111128
$classMetadata
112129
->method('getPropertyMetadata')
113130
->with('firstArgument')
@@ -129,42 +146,54 @@ public function testOutputWithPathArgument()
129146
Symfony\Component\Validator\Tests\Dummy\DummyClassOne
130147
-----------------------------------------------------
131148
132-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
133-
| Property | Name | Groups | Options |
134-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
135-
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | [ |
136-
| | | | "allowNull" => false, |
137-
| | | | "message" => "This value should not be blank.", |
138-
| | | | "normalizer" => null, |
139-
| | | | "payload" => null |
140-
| | | | ] |
141-
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | [ |
142-
| | | | "message" => "This value is not a valid email address.", |
143-
| | | | "mode" => null, |
144-
| | | | "normalizer" => null, |
145-
| | | | "payload" => null |
146-
| | | | ] |
147-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
149+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
150+
| Property | Name | Groups | Options |
151+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
152+
| - | Symfony\Component\Validator\Constraints\Expression | Default | [ |
153+
| | | | "expression" => "1 + 1 = 2", |
154+
| | | | "message" => "This value is not valid.", |
155+
| | | | "payload" => null, |
156+
| | | | "values" => [] |
157+
| | | | ] |
158+
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | [ |
159+
| | | | "allowNull" => false, |
160+
| | | | "message" => "This value should not be blank.", |
161+
| | | | "normalizer" => null, |
162+
| | | | "payload" => null |
163+
| | | | ] |
164+
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | [ |
165+
| | | | "message" => "This value is not a valid email address.", |
166+
| | | | "mode" => null, |
167+
| | | | "normalizer" => null, |
168+
| | | | "payload" => null |
169+
| | | | ] |
170+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
148171
149172
Symfony\Component\Validator\Tests\Dummy\DummyClassTwo
150173
-----------------------------------------------------
151174
152-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
153-
| Property | Name | Groups | Options |
154-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
155-
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | [ |
156-
| | | | "allowNull" => false, |
157-
| | | | "message" => "This value should not be blank.", |
158-
| | | | "normalizer" => null, |
159-
| | | | "payload" => null |
160-
| | | | ] |
161-
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | [ |
162-
| | | | "message" => "This value is not a valid email address.", |
163-
| | | | "mode" => null, |
164-
| | | | "normalizer" => null, |
165-
| | | | "payload" => null |
166-
| | | | ] |
167-
+---------------+--------------------------------------------------+---------+------------------------------------------------------------+
175+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
176+
| Property | Name | Groups | Options |
177+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
178+
| - | Symfony\Component\Validator\Constraints\Expression | Default | [ |
179+
| | | | "expression" => "1 + 1 = 2", |
180+
| | | | "message" => "This value is not valid.", |
181+
| | | | "payload" => null, |
182+
| | | | "values" => [] |
183+
| | | | ] |
184+
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | [ |
185+
| | | | "allowNull" => false, |
186+
| | | | "message" => "This value should not be blank.", |
187+
| | | | "normalizer" => null, |
188+
| | | | "payload" => null |
189+
| | | | ] |
190+
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | [ |
191+
| | | | "message" => "This value is not a valid email address.", |
192+
| | | | "mode" => null, |
193+
| | | | "normalizer" => null, |
194+
| | | | "payload" => null |
195+
| | | | ] |
196+
+---------------+----------------------------------------------------+---------+------------------------------------------------------------+
168197
169198
TXT
170199
, $tester->getDisplay(true)

0 commit comments

Comments
 (0)