Skip to content

Commit ef7ec9b

Browse files
committed
minor #38238 [Validator] stop using the deprecated at() PHPUnit matcher (xabbuh)
This PR was merged into the 5.1 branch. Discussion ---------- [Validator] stop using the deprecated at() PHPUnit matcher | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Commits ------- 0d0f92b7c6 stop using the deprecated at() PHPUnit matcher
2 parents d18a145 + 1a6a9cb commit ef7ec9b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Test/ConstraintValidatorTestCase.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Validator\ConstraintValidatorInterface;
2525
use Symfony\Component\Validator\ConstraintViolation;
2626
use Symfony\Component\Validator\ConstraintViolationInterface;
27+
use Symfony\Component\Validator\ConstraintViolationList;
2728
use Symfony\Component\Validator\Context\ExecutionContext;
2829
use Symfony\Component\Validator\Context\ExecutionContextInterface;
2930
use Symfony\Component\Validator\Mapping\ClassMetadata;
@@ -56,6 +57,8 @@ abstract class ConstraintValidatorTestCase extends TestCase
5657
protected $propertyPath;
5758
protected $constraint;
5859
protected $defaultTimezone;
60+
private $expectedViolations;
61+
private $call;
5962

6063
protected function setUp(): void
6164
{
@@ -74,6 +77,9 @@ protected function setUp(): void
7477
$this->validator = $this->createValidator();
7578
$this->validator->initialize($this->context);
7679

80+
$this->expectedViolations = [];
81+
$this->call = 0;
82+
7783
\Locale::setDefault('en');
7884

7985
$this->setDefaultTimezone('UTC');
@@ -107,6 +113,11 @@ protected function createContext()
107113
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
108114
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
109115
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
116+
$validator->expects($this->any())
117+
->method('validate')
118+
->willReturnCallback(function () {
119+
return $this->expectedViolations[$this->call++] ?? new ConstraintViolationList();
120+
});
110121

111122
$context = new ExecutionContext($validator, $this->root, $translator);
112123
$context->setGroup($this->group);
@@ -260,11 +271,7 @@ protected function expectViolationsAt($i, $value, Constraint $constraint)
260271
$validator->initialize($context);
261272
$validator->validate($value, $constraint);
262273

263-
$this->context->getValidator()
264-
->expects($this->at($i))
265-
->method('validate')
266-
->willReturn($context->getViolations())
267-
;
274+
$this->expectedViolations[] = $context->getViolations();
268275

269276
return $context->getViolations();
270277
}

0 commit comments

Comments
 (0)