stop using the deprecated at() PHPUnit matcher
This commit is contained in:
parent
9610daf1bc
commit
0d0f92b7c6
@ -29,7 +29,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"doctrine/collections": "~1.0",
|
"doctrine/collections": "~1.0",
|
||||||
"symfony/validator": "^4.4|^5.0",
|
"symfony/validator": "^4.4.12|^5.1.6",
|
||||||
"symfony/dependency-injection": "^4.4|^5.0",
|
"symfony/dependency-injection": "^4.4|^5.0",
|
||||||
"symfony/expression-language": "^4.4|^5.0",
|
"symfony/expression-language": "^4.4|^5.0",
|
||||||
"symfony/config": "^4.4|^5.0",
|
"symfony/config": "^4.4|^5.0",
|
||||||
|
@ -24,6 +24,7 @@ use Symfony\Component\Validator\Constraints\Valid;
|
|||||||
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||||
use Symfony\Component\Validator\ConstraintViolation;
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContext;
|
use Symfony\Component\Validator\Context\ExecutionContext;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
@ -56,6 +57,8 @@ abstract class ConstraintValidatorTestCase extends TestCase
|
|||||||
protected $propertyPath;
|
protected $propertyPath;
|
||||||
protected $constraint;
|
protected $constraint;
|
||||||
protected $defaultTimezone;
|
protected $defaultTimezone;
|
||||||
|
private $expectedViolations;
|
||||||
|
private $call;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
@ -74,6 +77,9 @@ abstract class ConstraintValidatorTestCase extends TestCase
|
|||||||
$this->validator = $this->createValidator();
|
$this->validator = $this->createValidator();
|
||||||
$this->validator->initialize($this->context);
|
$this->validator->initialize($this->context);
|
||||||
|
|
||||||
|
$this->expectedViolations = [];
|
||||||
|
$this->call = 0;
|
||||||
|
|
||||||
\Locale::setDefault('en');
|
\Locale::setDefault('en');
|
||||||
|
|
||||||
$this->setDefaultTimezone('UTC');
|
$this->setDefaultTimezone('UTC');
|
||||||
@ -107,6 +113,11 @@ abstract class ConstraintValidatorTestCase extends TestCase
|
|||||||
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
||||||
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
|
$translator->expects($this->any())->method('trans')->willReturnArgument(0);
|
||||||
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
|
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
|
||||||
|
$validator->expects($this->any())
|
||||||
|
->method('validate')
|
||||||
|
->willReturnCallback(function () {
|
||||||
|
return $this->expectedViolations[$this->call++] ?? new ConstraintViolationList();
|
||||||
|
});
|
||||||
|
|
||||||
$context = new ExecutionContext($validator, $this->root, $translator);
|
$context = new ExecutionContext($validator, $this->root, $translator);
|
||||||
$context->setGroup($this->group);
|
$context->setGroup($this->group);
|
||||||
@ -260,11 +271,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
|
|||||||
$validator->initialize($context);
|
$validator->initialize($context);
|
||||||
$validator->validate($value, $constraint);
|
$validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->context->getValidator()
|
$this->expectedViolations[] = $context->getViolations();
|
||||||
->expects($this->at($i))
|
|
||||||
->method('validate')
|
|
||||||
->willReturn($context->getViolations())
|
|
||||||
;
|
|
||||||
|
|
||||||
return $context->getViolations();
|
return $context->getViolations();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user