|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Validator\Tests\Constraints;
|
13 | 13 |
|
14 |
| -use Symfony\Component\Intl\Util\IntlTestHelper; |
15 | 14 | use Symfony\Component\Validator\Constraint;
|
16 |
| -use Symfony\Component\Validator\Constraints\AbstractComparison; |
17 | 15 | use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
18 | 16 | use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
19 |
| -use Symfony\Component\Validator\Tests\Constraints\Fixtures\TypedDummy; |
20 | 17 |
|
21 | 18 | class ComparisonTest_Class
|
22 | 19 | {
|
@@ -98,32 +95,6 @@ public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
|
98 | 95 | ]);
|
99 | 96 | }
|
100 | 97 |
|
101 |
| - /** |
102 |
| - * @dataProvider provideAllValidComparisons |
103 |
| - */ |
104 |
| - public function testValidComparisonToValue($dirtyValue, $comparisonValue) |
105 |
| - { |
106 |
| - $constraint = $this->createConstraint(['value' => $comparisonValue]); |
107 |
| - |
108 |
| - $this->validator->validate($dirtyValue, $constraint); |
109 |
| - |
110 |
| - $this->assertNoViolation(); |
111 |
| - } |
112 |
| - |
113 |
| - public static function provideAllValidComparisons(): array |
114 |
| - { |
115 |
| - // The provider runs before setUp(), so we need to manually fix |
116 |
| - // the default timezone |
117 |
| - $timezone = date_default_timezone_get(); |
118 |
| - date_default_timezone_set('UTC'); |
119 |
| - |
120 |
| - $comparisons = self::addPhp5Dot5Comparisons(static::provideValidComparisons()); |
121 |
| - |
122 |
| - date_default_timezone_set($timezone); |
123 |
| - |
124 |
| - return $comparisons; |
125 |
| - } |
126 |
| - |
127 | 98 | /**
|
128 | 99 | * @dataProvider provideValidComparisonsToPropertyPath
|
129 | 100 | */
|
@@ -169,144 +140,8 @@ abstract public static function provideValidComparisons(): array;
|
169 | 140 |
|
170 | 141 | abstract public static function provideValidComparisonsToPropertyPath(): array;
|
171 | 142 |
|
172 |
| - /** |
173 |
| - * @dataProvider provideAllInvalidComparisons |
174 |
| - */ |
175 |
| - public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $comparedValue, $comparedValueString, $comparedValueType) |
176 |
| - { |
177 |
| - // Conversion of dates to string differs between ICU versions |
178 |
| - // Make sure we have the correct version loaded |
179 |
| - if ($dirtyValue instanceof \DateTimeInterface) { |
180 |
| - IntlTestHelper::requireIntl($this, '57.1'); |
181 |
| - } |
182 |
| - |
183 |
| - $constraint = $this->createConstraint(['value' => $comparedValue]); |
184 |
| - $constraint->message = 'Constraint Message'; |
185 |
| - |
186 |
| - $this->validator->validate($dirtyValue, $constraint); |
187 |
| - |
188 |
| - $this->buildViolation('Constraint Message') |
189 |
| - ->setParameter('{{ value }}', $dirtyValueAsString) |
190 |
| - ->setParameter('{{ compared_value }}', $comparedValueString) |
191 |
| - ->setParameter('{{ compared_value_type }}', $comparedValueType) |
192 |
| - ->setCode($this->getErrorCode()) |
193 |
| - ->assertRaised(); |
194 |
| - } |
195 |
| - |
196 |
| - public function testInvalidComparisonToPropertyPathAddsPathAsParameter() |
197 |
| - { |
198 |
| - [$dirtyValue, $dirtyValueAsString, $comparedValue, $comparedValueString, $comparedValueType] = current($this->provideAllInvalidComparisons()); |
199 |
| - |
200 |
| - $constraint = $this->createConstraint(['propertyPath' => 'value']); |
201 |
| - $constraint->message = 'Constraint Message'; |
202 |
| - |
203 |
| - $object = new ComparisonTest_Class($comparedValue); |
204 |
| - |
205 |
| - $this->setObject($object); |
206 |
| - |
207 |
| - $this->validator->validate($dirtyValue, $constraint); |
208 |
| - |
209 |
| - $this->buildViolation('Constraint Message') |
210 |
| - ->setParameter('{{ value }}', $dirtyValueAsString) |
211 |
| - ->setParameter('{{ compared_value }}', $comparedValueString) |
212 |
| - ->setParameter('{{ compared_value_path }}', 'value') |
213 |
| - ->setParameter('{{ compared_value_type }}', $comparedValueType) |
214 |
| - ->setCode($this->getErrorCode()) |
215 |
| - ->assertRaised(); |
216 |
| - } |
217 |
| - |
218 |
| - /** |
219 |
| - * @dataProvider throwsOnInvalidStringDatesProvider |
220 |
| - */ |
221 |
| - public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $expectedMessage, $value) |
222 |
| - { |
223 |
| - $this->expectException(ConstraintDefinitionException::class); |
224 |
| - $this->expectExceptionMessage($expectedMessage); |
225 |
| - |
226 |
| - $this->validator->validate($value, $constraint); |
227 |
| - } |
228 |
| - |
229 |
| - public static function throwsOnInvalidStringDatesProvider(): array |
230 |
| - { |
231 |
| - $constraint = static::createConstraint([ |
232 |
| - 'value' => 'foo', |
233 |
| - ]); |
234 |
| - |
235 |
| - return [ |
236 |
| - [$constraint, \sprintf('The compared value "foo" could not be converted to a "DateTimeImmutable" instance in the "%s" constra
10000
int.', $constraint::class), new \DateTimeImmutable()], |
237 |
| - [$constraint, \sprintf('The compared value "foo" could not be converted to a "DateTime" instance in the "%s" constraint.', $constraint::class), new \DateTime()], |
238 |
| - ]; |
239 |
| - } |
240 |
| - |
241 |
| - /** |
242 |
| - * @dataProvider provideComparisonsToNullValueAtPropertyPath |
243 |
| - */ |
244 |
| - public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsString, $isValid) |
245 |
| - { |
246 |
| - $constraint = $this->createConstraint(['propertyPath' => 'value']); |
247 |
| - $constraint->message = 'Constraint Message'; |
248 |
| - |
249 |
| - $object = new ComparisonTest_Class(null); |
250 |
| - $this->setObject($object); |
251 |
| - |
252 |
| - $this->validator->validate($dirtyValue, $constraint); |
253 |
| - |
254 |
| - if ($isValid) { |
255 |
| - $this->assertNoViolation(); |
256 |
| - } else { |
257 |
| - $this->buildViolation('Constraint Message') |
258 |
| - ->setParameter('{{ value }}', $dirtyValueAsString) |
259 |
| - ->setParameter('{{ compared_value }}', 'null') |
260 |
| - ->setParameter('{{ compared_value_type }}', 'null') |
261 |
| - ->setParameter('{{ compared_value_path }}', 'value') |
262 |
| - ->setCode($this->getErrorCode()) |
263 |
| - ->assertRaised(); |
264 |
| - } |
265 |
| - } |
266 |
| - |
267 |
| - /** |
268 |
| - * @dataProvider provideComparisonsToNullValueAtPropertyPath |
269 |
| - */ |
270 |
| - public function testCompareWithUninitializedPropertyAtPropertyPath($dirtyValue, $dirtyValueAsString, $isValid) |
271 |
| - { |
272 |
| - $this->setObject(new TypedDummy()); |
273 |
| - |
274 |
| - $this->validator->validate($dirtyValue, $this->createConstraint([ |
275 |
| - 'message' => 'Constraint Message', |
276 |
| - 'propertyPath' => 'value', |
277 |
| - ])); |
278 |
| - |
279 |
| - if ($isValid) { |
280 |
| - $this->assertNoViolation(); |
281 |
| - } else { |
282 |
| - $this->buildViolation('Constraint Message') |
283 |
| - ->setParameter('{{ value }}', $dirtyValueAsString) |
284 |
| - ->setParameter('{{ compared_value }}', 'null') |
285 |
| - ->setParameter('{{ compared_value_type }}', 'null') |
286 |
| - ->setParameter('{{ compared_value_path }}', 'value') |
287 |
| - ->setCode($this->getErrorCode()) |
288 |
| - ->assertRaised(); |
289 |
| - } |
290 |
| - } |
291 |
| - |
292 |
| - public static function provideAllInvalidComparisons(): array |
293 |
| - { |
294 |
| - // The provider runs before setUp(), so we need to manually fix |
295 |
| - // the default timezone |
296 |
| - $timezone = date_default_timezone_get(); |
297 |
| - date_default_timezone_set('UTC'); |
298 |
| - |
299 |
| - $comparisons = self::addPhp5Dot5Comparisons(static::provideInvalidComparisons()); |
300 |
| - |
301 |
| - date_default_timezone_set($timezone); |
302 |
| - |
303 |
| - return $comparisons; |
304 |
| - } |
305 |
| - |
306 | 143 | abstract public static function provideInvalidComparisons(): array;
|
307 | 144 |
|
308 |
| - abstract public static function provideComparisonsToNullValueAtPropertyPath(); |
309 |
| - |
310 | 145 | abstract protected static function createConstraint(?array $options = null): Constraint;
|
311 | 146 |
|
312 | 147 | protected function getErrorCode(): ?string
|
|
0 commit comments