comparison vendor/symfony/validator/Test/ConstraintValidatorTestCase.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
119 } 119 }
120 120
121 protected function setObject($object) 121 protected function setObject($object)
122 { 122 {
123 $this->object = $object; 123 $this->object = $object;
124 $this->metadata = is_object($object) 124 $this->metadata = \is_object($object)
125 ? new ClassMetadata(get_class($object)) 125 ? new ClassMetadata(\get_class($object))
126 : null; 126 : null;
127 127
128 $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); 128 $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
129 } 129 }
130 130
131 protected function setProperty($object, $property) 131 protected function setProperty($object, $property)
132 { 132 {
133 $this->object = $object; 133 $this->object = $object;
134 $this->metadata = is_object($object) 134 $this->metadata = \is_object($object)
135 ? new PropertyMetadata(get_class($object), $property) 135 ? new PropertyMetadata(\get_class($object), $property)
136 : null; 136 : null;
137 137
138 $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath); 138 $this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
139 } 139 }
140 140
173 ->method('atPath') 173 ->method('atPath')
174 ->with($propertyPath) 174 ->with($propertyPath)
175 ->will($this->returnValue($validator)); 175 ->will($this->returnValue($validator));
176 $validator->expects($this->at(2 * $i + 1)) 176 $validator->expects($this->at(2 * $i + 1))
177 ->method('validate') 177 ->method('validate')
178 ->with($value, $this->logicalOr(null, array(), $this->isInstanceOf('\Symfony\Component\Validator\Constraints\Valid')), $group); 178 ->with($value, $this->logicalOr(null, [], $this->isInstanceOf('\Symfony\Component\Validator\Constraints\Valid')), $group);
179 } 179 }
180 180
181 protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null) 181 protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null)
182 { 182 {
183 $contextualValidator = $this->context->getValidator()->inContext($this->context); 183 $contextualValidator = $this->context->getValidator()->inContext($this->context);
190 ->with($value, $constraints, $group); 190 ->with($value, $constraints, $group);
191 } 191 }
192 192
193 protected function assertNoViolation() 193 protected function assertNoViolation()
194 { 194 {
195 $this->assertSame(0, $violationsCount = count($this->context->getViolations()), sprintf('0 violation expected. Got %u.', $violationsCount)); 195 $this->assertSame(0, $violationsCount = \count($this->context->getViolations()), sprintf('0 violation expected. Got %u.', $violationsCount));
196 } 196 }
197 197
198 /** 198 /**
199 * @param $message 199 * @param $message
200 * 200 *
222 * @var ConstraintViolationAssertion[] 222 * @var ConstraintViolationAssertion[]
223 */ 223 */
224 private $assertions; 224 private $assertions;
225 225
226 private $message; 226 private $message;
227 private $parameters = array(); 227 private $parameters = [];
228 private $invalidValue = 'InvalidValue'; 228 private $invalidValue = 'InvalidValue';
229 private $propertyPath = 'property.path'; 229 private $propertyPath = 'property.path';
230 private $plural; 230 private $plural;
231 private $code; 231 private $code;
232 private $constraint; 232 private $constraint;
233 private $cause; 233 private $cause;
234 234
235 public function __construct(ExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = array()) 235 public function __construct(ExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = [])
236 { 236 {
237 $this->context = $context; 237 $this->context = $context;
238 $this->message = $message; 238 $this->message = $message;
239 $this->constraint = $constraint; 239 $this->constraint = $constraint;
240 $this->assertions = $assertions; 240 $this->assertions = $assertions;
304 return new self($this->context, $message, $this->constraint, $assertions); 304 return new self($this->context, $message, $this->constraint, $assertions);
305 } 305 }
306 306
307 public function assertRaised() 307 public function assertRaised()
308 { 308 {
309 $expected = array(); 309 $expected = [];
310 foreach ($this->assertions as $assertion) { 310 foreach ($this->assertions as $assertion) {
311 $expected[] = $assertion->getViolation(); 311 $expected[] = $assertion->getViolation();
312 } 312 }
313 $expected[] = $this->getViolation(); 313 $expected[] = $this->getViolation();
314 314
315 $violations = iterator_to_array($this->context->getViolations()); 315 $violations = iterator_to_array($this->context->getViolations());
316 316
317 Assert::assertSame($expectedCount = count($expected), $violationsCount = count($violations), sprintf('%u violation(s) expected. Got %u.', $expectedCount, $violationsCount)); 317 Assert::assertSame($expectedCount = \count($expected), $violationsCount = \count($violations), sprintf('%u violation(s) expected. Got %u.', $expectedCount, $violationsCount));
318 318
319 reset($violations); 319 reset($violations);
320 320
321 foreach ($expected as $violation) { 321 foreach ($expected as $violation) {
322 Assert::assertEquals($violation, current($violations)); 322 Assert::assertEquals($violation, current($violations));